Delicious Digg Facebook Favorites More Stumbleupon Twitter

Tuesday, 28 August 2012

loops


           Loops of C-Programming language



        Loop is a statement, it calls itself more than one time,
        when the condition gets satisfied. 
                                  (or)
       C loop statement is used when you want to execute
       a block of code repeatedly with checked condition
       before making an iteration.

        By using loop we can reduce the duplicate statements.

       Loops are divided into 3 types.

       * while loop.

       * do-while loop.

       * for loop. 

Monday, 27 August 2012

program for swapping 2 numbers


               Program for Swapping 2 Numbers

             #include<stdio.h>
             main()
             {
                  int a,b,temp;
                  clrscr();
                  printf("enter a,b values:");
                  scanf("%d%d",&a,&b);
                  temp = a;
                        a = b;
                  b = temp;
                  printf("after swaping a,b values:%d%d",a,b);
                  getch();
             }
           
             output :-

                       enter a,b values : 10 20
                       after swaping a,b values : 20 10
                      










 

program for even/odd number


                  Program for even/odd Number

           #include<stdio.h>
           main()
          {
              int a;
              clrscr();
              printf("enter the value of a:");
              scanf("%d",&a);
              if(a%2 == 0)
              printf(" even");
              else
              printf("odd");
              getch();
           }

         output :-

                  enter the value of a: 7
                  odd

ladder if-else condition


                        Ladder if-else Condition

               It is used for comparision between the variables,
               and sub variables.

               syntax:-

                             if(condition)
                            {
                             if(condition)
                             {
                              statements;
                             }
                             else if(condition)
                             {
                             statements;
                             }
                            else if(condition)
                            {
                            statements;
                             }
                            else
                            {
                            statements;
                            }
                            }
                            else
                            {
                            statement;
                             }

            Example:-
                            #include<stdio.h>
                            main()
                           {
                                  int a;
                                  clrscr();
                                  printf("enter a value:");
                                  scanf("%d",&a);
                                  if(a>=35)

                                  {
                                     printf("pass");
                                     if((a >=35)&(a<=50))
                                     printf("c grade");
                                     else if((a>=50)&(a<=75))
                                     printf("b grade");
                                     else
                                     printf("a grade");

                                  }
                                  else

                                     printf("fail");
                                  getch();
                            }





                                             output:-



                         

        

nested if-else condition


                      Nested if-else Condition

                It is used for comparision between more than 
                two  variables.

                syntax:- 
    
                             if(condition)
                             {
                                  statements;
                              }
                              else if(condition)
                              {
                                  statements;
                               }
                               else if(condition)
                               {
                                  statements;
                                }
                                else
                                {
                                   statements;
                                 }

                  Example:-  
                                    #include<stdio.h>
                                    main()
                                   {
                                      int a,b,c,d;
                                      clrscr();
                                      printf("enter a,b,c,d values:");
                                      scanf("%d%d%d%d",&a,&b,&c,&d);
                                      if((a>b)&(a>c)&(a>d))
                                      printf("a is big");
                                      else if((b>a)&(b>c)&(b>d))
                                      printf("b is big");
                                      else if((c>a)&(c>b)&(c>d))
                                      printf("c is big");
                                      else
                                      printf("d is big");
                                   getch();
                                   }





                                      
                 output:-

                     

                          

Sunday, 26 August 2012

if-else condition


                      if-else Condition

                It is used for comparision between only 
                two  variables.

                syntax:- 
    
                             if(condition)
                             {
                                  statements;
                              }
                              else
                              {
                                  statements;
                               }

                  Example:-  
                                    #include<stdio.h>
                                    main()
                                   {
                                      int a,b;
                                      clrscr();
                                      printf("enter a,b values:");
                                      scanf("%d%d",&a,&b);
                                      if(a>b)
                                      printf("a is big");
                                      else
                                      printf("b is big");
                                      getch();
                                   }

                 


output:-

           





                          

if-else multiple statement condition


           if-else multiple statement condition

                It is used for comparision between more than 
                two  variables,by using symbols(?,:).

                syntax:- 
    
               condition ? printf("statements"):printf("statements");
                              

                  Example:-  
                                    #include<stdio.h>
                                    main()
                                   {
                                      clrscr();
           ((3>4)&(3>7)) ?  printf("true"):printf("false");
                                   getch();
                                   }


                      

output:-