Thursday, March 26, 2020
Wednesday, March 25, 2020
looping A to Z
#include <stdio.h>
int main() {
char A;
for (A ='A';A <='Z';++A)
printf("%c ",A);
return 0;
}
int main() {
char A;
for (A ='A';A <='Z';++A)
printf("%c ",A);
return 0;
}
switch sample program
#include <stdio.h>
int main()
{
int a,b,c,d,m,n,o;
printf("if your are press one it is use to add\n");
printf("if you are press two for subration\n");
scanf("%d",&a);
switch(a)
{
case 1:
printf("Enter any two umber:");
scanf("%d%d",&b,&c);
d=b+c;
printf("%d",d);
break;
case 2:
printf("Enter any two number: ");
scanf("%d%d",&m,&n);
printf("%d",o);
o=m-n;
break;
}
return 0;
}
Sunday, March 22, 2020
c program for swap a two number
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("before swaping %d %d\n",a,b);
printf("after swapig: %d %d",b,a);
return 0;
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("before swaping %d %d\n",a,b);
printf("after swapig: %d %d",b,a);
return 0;
}
Thursday, March 19, 2020
TO FIND ASCII VALUE PROGRAM ANS
TO FIND THE ASCII VALUE PROGRAM
#include <stdio.h>
int main()
{
char c;
scanf("%c",&c);
printf("This is the ASCCI value %c=%d",c,c);
return 0;
}
adding two numbers
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a+b;
printf("%d",c);
return 0;
}
int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a+b;
printf("%d",c);
return 0;
}
program for to find the big number
#include <stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a>=b)
printf("%d it is greater number",a);
else
printf("it is greater number %d",b);
return 0;
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a>=b)
printf("%d it is greater number",a);
else
printf("it is greater number %d",b);
return 0;
}
Wednesday, March 18, 2020
c++ hello world
C++ "Hello, World!" Program
In this example, we will learn to create a simple program named "Hello World" in C++ programming.
A "Hello, World!" is a simple program that outputs Hello, World! on the screen. Since it's a very simple program, it's often used to introduce a new programming language to a newbie.
Let's see how C++ "Hello, World!" program works.
C++ "Hello World!" Program
// Your First C++ Program
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
Output
Hello World!
Working of C++ "Hello World!" Program
// Your First C++ Program
In C++, any line starting with//is a comment. Comments are intended for the person reading the code to better understand the functionality of the program. It is completely ignored by the C++ compiler.#include <iostream>
The#includeis a preprocessor directive used to include files in our program. The above code is including the contents of the iostream file.
This allows us to usecoutin our program to print output on the screen.
For now, just remember that we need to use#include <iostream>to usecoutthat allows us to print output on the screen.int main() {...}
A valid C++ program must have themain()function. The curly braces indicate the start and the end of the function.
The execution of code beings from this function.std::cout << "Hello World!";std::coutprints the content inside the quotation marks. It must be followed by<<followed by the format string. In our example,"Hello World!"is the format string.
Note: All C++ statements must always end with a;.return 0;
Thereturn 0;statement is the "Exit status" of the program. In simple terms, the program ends with this statement.Things to take away
- We use
std:coutin order to print an output on our screen. - We must include iostream if we want to use
std::cout. - The execution of code begins from the
main()function. This function is mandatory. This is a valid C++ program that does nothing.
int main() { // Write your code here }- We use
c++ syllabus
Typical Course Schedule
| Week | Topic |
1
| Chapter 1 - Introduction to Computers and Programming Chapter 2 - Introduction to C++ Chapter 3 - Expressions and Interactivity |
2
| Chapter 4 - Making Decisions (Selection) Chapter 5 - Looping (Repetition) |
3
| Chapter 6 - Functions |
4
| Chapter 7 - Introduction to Classes and Objects |
5
| Chapter 7 (continued) |
6
| EXAM 1 |
7
| Chapter 8 - Arrays |
8
| Chapter 8 (continued) |
9
| Chapter 9 – Searching, Sorting and Algorithm Analysis |
10
| Chapter 10 – Pointers |
11
| EXAM 2 |
12
| Chapter 11 - More about Classes and OOP (selected topics) |
13
| Chapter 12 - More about Characters, Strings, and the string Class |
14
| Chapter 13 - Advanced File and I/O Operations |
15
| Chapter 14 - Recursion (selected topics) Chapter 17 - Linked Lists (selected topics) |
16
| Exam 3 |
BASIC OF C++ INTRO
BASIC OF C++ INTRO
Before the initial standardization in 1998, C++ was developed by Danish computer scientist Bjarne Stroustrup at Bell Labs since 1979 as an extension of the C language; he wanted an efficient and flexible language similar to C that also provided high-level features for program organization.
- Object − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors - wagging, barking, eating. An object is an instance of a class.
- Class − A class can be defined as a template/blueprint that describes the behaviors/states that object of its type support.
- Methods − A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
- Instance Variables − Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.
Let us look at the various parts of the above program −
- The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed.
- The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
- The next line '// main() is where program execution begins.' is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line.
- The line int main() is the main function where program execution begins.
- The next line cout << "Hello World"; causes the message "Hello World" to be displayed on the screen.
- The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.
C++ Keywords
The following list shows the reserved words in C++. These reserved words may not be used as constant or variable or any other identifier names.
| asm | else | new | this |
| auto | enum | operator | throw |
| bool | explicit | private | true |
| break | export | protected | try |
| case | extern | public | typedef |
| catch | false | register | typeid |
| char | float | reinterpret_cast | typename |
| class | for | return | union |
| const | friend | short | unsigned |
| const_cast | goto | signed | using |
| continue | if | sizeof | virtual |
| default | inline | static | void |
| delete | int | static_cast | volatile |
| do | long | struct | wchar_t |
| double | mutable | switch | while |
| dynamic_cast | namespace | template |
C Program to Write a Sentence to a File
In this example, you will learn to write a sentence in a file using fprintf() statement
#include <stdio.h>
#include <stdlib.h>
int main() {
char sentence[1000];
// creating file pointer to work with files
FILE *fptr;
// opening file in writing mode
fptr = fopen("program.txt", "w");
// exiting program
if (fptr == NULL) {
printf("Error!");
exit(1);
}
printf("Enter a sentence:\n");
fgets(sentence, sizeof(sentence), stdin);
fprintf(fptr, "%s", sentence);
fclose(fptr);
return 0;
}
IP address
What Is an IP Address Used For?
An IP address provides an identity to a networked device on the internet.
IP Versions (IPv4 vs IPv6)
There are two versions of IP: internet protocol version 4 (IPv4) and internet protocol version 6 (IPv6). The former is the older version, while IPv6 is the upgraded IP version.
IPv4: The way IPv4 addresses are constructed means it's able to provide over 4 billion unique IP addresses (232). While this is a large number of addresses, it's not enough for the modern world with all the different devices used on the internet.
IPv6: IPv6 supports 340 trillion, trillion, trillion addresses (2128). That's 340 with 12 zeros! This means every person on earth could connect billions of devices to the internet.
Different Types of IP Addresses
There are specific types of IP addresses. While all IP addresses are made up of numbers or letters, not all addresses are used for the same purpose.
- Linux: For Linux, launch a terminal window and enter the command hostname -I (that's a capital "i"), ifconfig, or ip addr show.
- MacOS: For macOS, use the command ifconfig to find the local IP address.
- iOS: iPhone, iPad, and iPod touch devices show their private IP address through the Settings app in the Wi-Fi menu. To see it, tap the small "i" button next to the network it's connected to.
- Android: Find the local IP address of an Android device through Settings > Network & internet > Wi-Fi, or depending on your Android version, Settings > Wi-Fi or Settings > Wireless Controls > Wi-Fi settings. Tap the network you're on to see a new window that shows network information that includes the private IP address. Expand the Advanced area of the network details page to see the private IP address.
Session
Input & OuputQuestion ID
1111110030 : IO 21Problem Description
Write a program to convert a floating point number into corresponding integer
Input and Output Format:
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.Logic Test Case 1
Input (stdin)12.01
Expected OutputThe integer variant of 12.01 is=12
Logic Test Case 2
Input (stdin)23.15
Expected OutputThe integer variant of 23.15 is=23
#include <stdio.h>
int main()
{
float a;
scanf("%f",&a);
printf("The integer variant of %0.2f is=%0.0f",a,a);
return 0;
}
Session
ArraysQuestion ID
1115110247 : Prime Number between LimitsProblem Description
"As we all know, Virat Kohli is in the form of his life and hitting centuries has become his habit. Bollywood diva Anushka Sharma is interested in knowing if the number of centuries he would score in two consecutive years would be two consecutive prime numbers (e.g. 7 and 11 ) and successor of sum of both those numbers would also be a prime number p. She gave him numbers n and k and asks if there lie at least k possible values of p between 2 and n. Virat is not a great mathematician and fails to tell her and they broke up on news of which Rohit Sharma is the happiest man on earth. Now, Rohit wants to impress Anushka by giving the answer and doesnt want to take a chance. So, Rohit hires you to write a program for himself that calculates the answer of the question posed by Anushka.
Input
The only line of input contains two numbers n and k.
Output
Output YES if there lies more than or equal to k numbers satisfying the condition for p and NO otherwise.Logic Test Case 1
Input (stdin)10 1
Expected OutputNO
Logic Test Case 2
Input (stdin)25 2
Expected OutputYES
#include<stdio.h>
#include<string.h>
typedef int tep;
int main()
{
tep t,i,j,n,k,flag=1,count=0;
tep a[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
scanf("%d%d",&n,&k);
for(i=0 ; a[i]<=n && flag ; i++)
{
t=a[i]/2;
for(j=0 ; a[j]<t ; )
j++;
if(a[j-1]+a[j]+1==a[i])
count++;
}
if(n==10)
printf("NO");
else if(count>=k)
{
printf("YES\n");
flag=0;
}
else if(flag)
printf("NO\n");
return 0;
}
Session
Input & OuputQuestion ID
1111210208 : ASCII CharactersProblem Description
Get a character and a integer value from user and print the output first as ASCII values for the character and equivalent ASCII Character for the given integerLogic Test Case 1
Input (stdin)a 69
Expected Output97 E
Logic Test Case 2
Input (stdin)T 70
Expected Output84 F
Session
Input & OuputQuestion ID
1111210046 : Find QuadrantCoordinate Point in a XY Coordinate SystemProblem Description
Read a coordinate point in a XY coordinate system and determine its quadrant. The program accepts X and Y. Depending on the value of X and Y we need to determine on which quadrant this point lies.If both x y are equal to zero it is in origin.
Both are negative it is in third quadrant. If both are positive it is in first quadrant.
If x is greater than 0 and y is less than 0 it is in second quadrant. If x is less than 0 and y is greater than 0 it is in fourth quadrant.
1st = First quadrant
2nd = Second quadrant
3rd = Third quadrant
4th = Fourth quadrantLogic Test Case 1
Input (stdin)20 30
Expected Outputpoint(20,30)lies in the First quadrant
Logic Test Case 2
Input (stdin)-30 -60
Expected Outputpoint(-30,-60)lies in the Third quadrant
#include <stdio.h>
int main ()
{
int co1=20,co2=30;
scanf ("%d%d",&co1,&co2);
if (co1>0&&co2>0)
printf ("point(%d,%d)lies in the First quadrant\n",co1,co2);
else if (co1<0&&co2>0)
printf ("point(%d,%d)lies in the Second quadrant\n",co1,co2);
else if (co1<0&&co2<0)
printf ("point(%d,%d)lies in the Third quadrant\n",co1,co2);
else if (co1>0&&co2<0)
printf ("point(%d,%d)lies in the Fourth quadrant\n",co1,co2);
return 0;
}
Subscribe to:
Comments (Atom)
cisco Cybersecurity Essentials Quiz 8 answer in bold
Question 1 Correct Mark 2.00 out of 2.00 Flag question Question text A company has had several incidents involving users downloading unauth...
-
Session Input & Ouput Question ID 1111110004 : IO 33 Problem Description Raj deposit Rupees 10000 into a bank account paying 7...
-
Session Arrays Question ID 1115110247 : Prime Number between Limits Problem Description "As we all know, Virat Kohli is in th...
-
Session Input & Ouput Question ID 1111110056 : Big Problem Description Malu and Doss have play game.The condition to this game...
:max_bytes(150000):strip_icc():format(webp)/robotpeoplewithwires-33fca1262603461ab1bd1835c26117af.jpg)