• C language

    do…while Loop In C

    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 >…

  • C language

    Simple while Loop In C

    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; }…

  • C language

    Basic for Loop In C

    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…

  • C language

    Print The Largest And Smallest Using Global Declaration

    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…

  • C language

    Swapping Of Two Numbers Using Temporary Variable, Without Temp Variable, Using Bitwise Operator, Using Multiplication And Division

    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 =…

  • C language

    Reverse The Case Of Input Character

    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…

  • C language

    Check If Input Character Is A Vowel Using Switch Case

    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…

  • C language

    Switch Case With Break Statement

    switch() can only contain char and int. break is used to exit from switch statement. switch case can be without default case. In switch case char variable is always initialized within ”(single quotes). If there is no break statement then the cases following the matched case other than default will get executed. If there is no any match case then default will be executed. Syntax switch(expression) { case value1: block1; break; case value2: block2; break; case value3: block3; break; case value4: block4; break; default: defaultblock; break; } Example is below :: #include<stdio.h> #include<conio.h> void main() { char grade; clrscr(); printf("Enter your grade:\n");…

  • C language

    else if Ladder In C

    Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are, Simple if statement if….else statement Nested if….else statement Using else if statement Syntax if(expression1) { statement block1; } else if(expression2) { statement block2; } else if(expression3 ) { statement block3; } else { default statement; } The expression is tested from the top(of the ladder) to downwards. As soon as a true condition is found, the statement associated with it is executed. Example is shown below :: #include <stdio.h> #include<conio.h> void main( ) { int a; clrscr();…