Saturday, 26 May 2012

For Loop in c

When you want to do any operation for multiple times, this time you may use for operation in c. e.g. if you want to write "Hello World" on the screen for hundred times you can use this loop operation.

here is the program
#include<stdio.h>
int main(){
        int i;
        for ( i=0; i<=100; i++ )
       {
           printf("Hello World !!!\n");
       
       
}
       system("PAUSE");
      return 0;
}

Wednesday, 16 May 2012

Switch case operation in c

Todaye we have parcticed on switch case operation in c.
here is the code block:

#include <stdio.h>

main()
{
   char option;
  printf("Write your option(Y/N): ");
    scanf("%c",&option);
 switch(option)
 {
    case 'Y':
         printf("Yes, we have a class on friday\n");
         break;
    case 'N':
        printf("No, we don't have any class on friday\n");
        break;
    default:
         printf("write the correct option\n");
         break;
   }
system("PAUSE");
return 0;
}



Saturday, 12 May 2012

If and else in c

If you want to compare two or more options, this time you can implement if.. else . the general syntex for if..else is

if ( condition ) {
   expr_set1;
}
else  {
   expr_set2;
}

you can remember from spreadsheet program, whre we used if function for TRUE & FALSE.

The code block of our last solved proram is given below

#include<stdio.h>
int main(){
        int i,j, result;
        printf("Write the two numbers you want compare:");
        scanf("%d %d",&i, &j);
        result = i-j;
        if ( result > 0 )
                printf("%d is greater than %d\n",i,j);
        
        else 
          if ( result < 0 )
             printf("%d is greater than %d\n",i,j);        
       
        else
            if ( result = 0 )
               printf("Both the numbers are equal\n");

     system ("PAUSE");       
     return 0;
}
Here is the screenshot of the program run with the two numbers 45 &90