- A virus

Post Top Ad

Responsive Ads Here
Share This

W.A.P FOR  USE OF IF - ELSE STATEMENT
#include <stdio.h>       

int main()                            /* Most important part of the program!  */
{
    int age;                          /* Need a variable... */
 
    printf( "Please enter your age" );  /* Asks for age */
    scanf( "%d", &age );                 /* The input is put in age */
    if ( age < 100 ) {                  /* If the age is less than 100 */
        printf ("You are pretty young!\n" ); /* Just to show you it works... */
    }
    else if ( age == 100 ) {            /* I use else just to show an example */
        printf( "You are old\n" );      
    }
    else {
        printf( "You are really old\n" );     /* Executed if no other statement is */
    }
  return 0;
}

FLOW CHART OF IF -ELSE STATEMENT
                                                       
W.A.P FOR USE OF IF ELSE STATEMENT

    main () {
   /* local variable definition */
   int a = 100;
 
   /* check the boolean condition */
   if( a < 20 ) {
      /* if condition is true then print the following */
      printf("a is less than 20\n" );
   }
   else {
      /* if condition is false then print the following */
      printf("a is not less than 20\n" );
   }
   
   printf("value of a is : %d\n", a);
 
   return 0;
}
a is not less than 20;
value of a is : 100

             FLOW CHART OF IF -ELSE STATEMENT
                           
                        
W.A.P FOR USE OF IF STATEMENT
#include <stdio.h>
      int main(){
      int num;
      printf("Enter a number to check.\n");
      scanf("%d",&num);
      if(num<0) {      /* checking whether number is less than 0 or not. */ 
            printf("Number = %d\n",num); 
      }  
/*If test condition is true, statement above will be executed, otherwise it will not be executed */
      printf("The if statement in C programming is easy.");
return 0;
}
Output
Enter a number to check.
-2
Number = -2

   
                   FLOW CHART OF IF - STATEMENT

                                    
W.A.P FOR USE OF IF STATEMENT
#include <stdio.h>
int main()
{
      int x, y;
      printf("enter the value of x:");
      scanf("%d", &x);
      printf("enter the value of y:");
      scanf("%d", &y);
      if (x y)
      {
           printf("x is greater than y");
      }
      printf("Hi, I'm out of all try blocks");
     return 0;
}
Output
enter the value of x: 12
enter the value of y: 12
x is equal to y
Hi, Im out of all try blocks
                   FLOW CHART OF IF – STATEMENT
             

W.A.P FOR USE OF ELSE IF LADDER STATEMENT
#include <iostream>
using namespace std;

int main ()
{
   // declare local variable
   int marks = 55;

   // check the boolean condition
   if( marks >= 80 )
   {
       // if 1st condition is true
       cout << "U are 1st class !!" << endl;
   }
   else if( marks >= 60 && marks < 80)
   {
       // if 2nd condition is false
       cout << "U are 2nd class !!" << endl;
   }
   else if( marks >= 40 && marks < 60)
   {
       // if 3rd condition is false
       cout << "U are 3rd class !!" << endl;
   }
   else
   {
       // none of condition is true
       cout << "U are fail !!" << endl;
   }

   return 0;
}
Output:
U are 3rd class !!
        FLOW CHART OF ELSE IF  LADDER STATEMENT
          
 W.A.P FOR USE OF SWITCH STATEMENT

int main()
{
     int num=2;
     switch(num+2)
     {
         case 1:
           printf("Case1: Value is: %d", num);
         case 2:
           printf("Case1: Value is: %d", num);
         case 3:
           printf("Case1: Value is: %d", num);
         default:
           printf("Default: Value is: %d", num);
    }
    return 0;
}
Output:
Default: value is: 2

FLOW CHART OF SWITCH STATEMENT
      
           W.A.P FOR USE OF FOR STATEMENT
 
#include <stdio.h>
int main(){
    int n, count, sum=0;
    printf("Enter the value of n.\n");
    scanf("%d",&n);
    for(count=1;count<=n;++count)  //for loop terminates if count>n
    {
        sum+=count;    /* this statement is equivalent to sum=sum+count */
    }
    printf("Sum=%d",sum);
    return 0;
}
 
Output
Enter the value of n.
19
Sum=190
         FLOW CHART OF FOR STATEMENT

                     
           W.A.P FOR USE OF WHILE STATEMENT
#include <stdio.h>
 
int main () {
 
   /* local variable definition */
   int a = 10;
 
   /* while loop execution */
   while( a < 20 ) {
      printf("value of a: %d\n", a);
      a++;
   }
 
   return 0;
}
OUTPUT: -
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

         FLOW CHART OF WHILE STATEMENT
                           
W.A.P FOR USE OF DO- WHILE STATEMENT
#include <stdio.h>    
#include <conio.h>    
void main(){    
int i=1;  
clrscr();    
  
do{  
printf("%d \n",i);  
i++;  
}while(i<=10);  
    
getch();    
}    

           FLOW CHART OF DO-WHILE STATEMENT
               
W.A.P FOR USE OF BREAK STATEMENT
#include <stdio.h>

int main () {

   /* local variable definition */
   int a = 10;

   /* while loop execution */
   while( a < 20 ) {
  
      printf("value of a: %d\n", a);
      a++;
                
      if( a > 15) {
         /* terminate the loop using break statement */
         break;
      }
                
   }

   return 0;
}
OUTPUT: -
value of a: 10
value of a: 11
FLOW CHART OF BREAK STATEMENT
                     
        W.A.P FOR USE OF CONTINUE STATEMENT
#include <stdio.h>

int main () {

   /* local variable definition */
   int a = 10;

   /* do loop execution */
   do {
  
      if( a == 15) {
         /* skip the iteration */
         a = a + 1;
         continue;
      }
                
      printf("value of a: %d\n", a);
      a++;
    
   } while( a < 20 );

   return 0;
}
OUTPUT: -
value of a: 10
value of a: 11
             FLOW CHART OF CONTINUE STATEMENT
                              
        W.A.P FOR USE OF GOTO STATEMENT
#include <stdio.h>

int main () {

   /* local variable definition */
   int a = 10;

   /* do loop execution */
   LOOP:do {
  
      if( a == 15) {
         /* skip the iteration */
         a = a + 1;
         goto LOOP;
      }
                
      printf("value of a: %d\n", a);
      a++;
    
   }while( a < 20 );

   return 0;
}
OUTPUT: -
value of a: 10
value of a: 11
           
             FLOW CHART OF GOTO STATEMENT

                                

No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages