In this program,it will takeĀ two integers (divisor and dividend) and find the quotient and remainder. To compute quotient and remainder, both divisor and dividend should be integers. #include <iostream> using namespace std; int main() { int divisor, dividend, quotient, remainder; cout << "Enter dividend: "; cin >> dividend; cout << "Enter divisor: "; cin >> divisor; quotient = dividend / divisor; remainder = dividend % divisor; cout << "Quotient = " << quotient << endl; cout << "Remainder = " << remainder; return 0; } OutPut Enter dividend: 17 Enter divisor: 4 Quotient = 4 Remainder = 1
-
-
In this program, two integer values taken from user and then sum of this values are stored in another variavle and then print it. #include <iostream> using namespace std; int main() { int firstNo, secondNo, sumOfTwoNo; cout << "Enter two integer values: "; cin >> firstNo >> secondNo; sumOfTwoNo = firstNo + secondNo; cout << firstNo << " + " << secondNo << " = " << sumOfTwoNo; return 0; } OutPut Enter two integer values: 4 5 4 + 5 = 9
-
cin>> is used to take value from the user. cout<< is used to print value. #include <iostream> using namespace std; int main() { int no; cout << "Enter an integer value: "; cin >> no; cout << "You entered " << no; return 0; } OutPut Enter an integer value: 23 You entered 23
-
As discussed before, loop contains three part Intialization Condition Checking Incrementation Or Decrementation do…while loop is also called exit control loop, it means that the statement of loop are always executed once even if the condition is false. In this while is ended by semicolon(;). Syntax variable=0; do { //statement variable++; or variable--; //increment or decrement }while(condition); Example is given below #include<stdio.h> #include<conio.h> void main() { int i = 10; // declaration and initialization at the same time clrscr(); do // do contains the actual code and the updation { printf("i = %d\n",i); i = i-1; // updation }while(i >…
-
As we discussed before the loop have three parts. Initialization Condition Checking Increment Or Decrement Part while loop is known as entry control loop, in this if the condition is true then the statement inside loop will be executed. Syntax variable=0; while(condition) { code statement variable++; or variable--; //increment or decrement part } Example is below #include<stdio.h> #include<conio.h> void main() { int i = 0; // declaration and initialization at the same time clrscr(); printf("\nPrinting numbers using while loop from 0 to 9\n\n"); /* while i is less than 10 */ while(i<10) { printf("%d\n",i); i++; // same as i=i+1; }…
-
for loop consists of three parts in a sequence. Initialization: Use to initialize the loop variable. Condition: It is checked after each iteration as an entry point to the loop. Increment or Decrement: Incrementing or Decrementing the loop variable to eventually terminate the loop not satisfying the loop condition. Remember that the loop condition checks the conditional statement before it loops again. Syntax: for(initialization, condition, incrementation or decrementation) { code statements; } Example is give below #include<stdio.h> #include<conio.h> void main() { //Always declare the variables before using them int i = 0; // declaration and initialization at the same time…
-
Some important points to be note about Global variable declaration are: It can be used anywhere within the program. Unlike local variables that can be used within the scope of a particular function. & is used to assign the input value to the variable and store it at that particular location. %0nd is used to represent numbers in n digit format with leading 0’s. #include<stdio.h> #include<conio.h> int a,b; void main() { clrscr(); printf("Enter the two values to find the greatest and smallest number: \n"); scanf("%d%d", &a, &b); if(a == b) printf("\n\nBoth are equal"); else if(a < b) { printf("\n\nThe largest…
-
Swapping means change the value of two variables with one another. There is basically four ways to perform swapping that are listed below. Using Temporary Variable Without Using Temporary Variable Using Bitwise Operator Using Multiplication And Division Using Temporary Variable In this, the anothe temporary variable is used. The value of first variable is assign to temporary variable. Then the value of second variable is assign to first and value of temporary variable is assign to second variable. #include<stdio.h> #include<conio.h> void main() { int x = 10, y = 15, temp; clrscr(); temp = x; x = y; y =…
-
getchar() is similar to scanf(). islower() is system defined function under ctype.h header file which check if the character is in lowercase or not. toupper() converts the input parameter into equivalent uppercase char. putchar() is similar to printf(). #include<stdio.h> #include<conio.h> #include<ctype.h> // for use system defined function islower() & toupper() void main() { char alphabet; clrscr(); printf("Enter an alphabet : "); putchar('\n'); // to move to next Line alphabet=getchar(); printf("\n\nReverse case of %c is : ",alphabet); if(islower(alphabet)) { putchar(toupper(alphabet)); } else { // must be an uppercase character printf("%c",tolower(alphabet)) ; } getch(); } OutPut Enter an alphabet : s Reverse…
-
The below program is check the entered character, if it is vowel then it will print the entered character is vowel, otherwise it will print that the entered character is not vowel. #include<stdio.h> #include<conio.h> void main() { char ch; clrscr(); printf("Enter A Character : "); scanf("%c", &ch); switch(ch) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': printf("\n\n%c is a Vowel.\n\n", ch); break; default: printf("%c is not a Vowel.\n\n", ch); } getch(); } OutPut Enter A Character : a a is a Vowel. Enter A Character : z…