Delicious Digg Facebook Favorites More Stumbleupon Twitter

Thursday 30 August 2012

Reverse floyds triangle


         Reverse floyds triangle :-


       #include<stdio.h>
       main()
      {

       int i,j,k;
       i=7;
       for(j=3;j>=0;j--)
      {
       for(k=0;k<=j;k++)
      {
       printf("%d ",(i+k));
      }
       i=i-j;
       printf("\n");
      }
      getch();

      }

Program to print multiplication table


     Program to print multiplication table :-

#include<stdio.h>
main()
{
 int r,i,j,k; 
 printf("Enter the number range: ");
 scanf("%d",&r);
 for(i=1;i<=r;i++)
{
 for(j=1;j<=10;j++)         
 printf("%d*%d=%d ",i,j,i*j);
 printf("\n");
 }
  return 0;
}

Palindrome number


    Palindrome number:-

 
  #include <stdio.h>
  main()
 {
   int n, n1, rev = 0, rem;
   printf("Enter any number: \n");
   scanf("%d", &n);
   n1 = n;
   while (n > 0)
 {
   rem = n % 10;
   rev = rev * 10 + rem;
   n = n / 10; }
   if (n1 == rev)
 {
   printf("Given number is a palindromic number");
 }
   else
{
 printf("Given number is not a palindromic number");
 }
 return 0;
}

Check prime number up to n


     Check prime number up to n:-

#include<stdio.h>
main()

int num,i,count,n;
printf("Enter max range: ");
scanf("%d",&n);
for(num = 1;num<=n;num++)

count = 0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0 && num!= 1)  
printf("%d ",num);
}
return 0;
}

Check prime number up to 100



   Check prime number up to 100 :-

#include<stdio.h>
main()
{
int n,i,count;
for(n = 1;n<=100;n++)
{
count = 0;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
count++;break;
}
if(count==0 && n!= 1)
printf("%d ",n);
}
return 0;
}
}

program for prime number



        prime number:-


#include<stdio.h>
int main()
{
int n,i,count=0;
printf("Enter a number: ");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
count++;
break;
}
}
if(count==0 && n!= 1)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
return 0;
}

output:-
                Enter a number: 7
                7 is a prime number

program for fibonacci series


  Program for Fibonacci series

#include<stdio.h>
main()
{
   int a,b,c,i;
   clrscr();
   a=0;
   b=1;
   printf("fibonacci series is\n:%d\t%d\t",a,b);
   for(i=0;i<5;i++)
   {
           c=a+b;
           a=b;
           b=c;
           printf("\t%d",c);
   }
   getch();
 }


output :-  0 1 1 2 3 5 8



 

Tuesday 28 August 2012

a program for "for loop"



              A Program for "for loop"

      Syntax :- 

                     {
                        for( initialization;condition;incrementation/
                                               decrementation)
                        statements;
                     }
     Example :-


                      #include<stdio.h>
                     main()
                     {
                        int i;
                        clrscr();
                        for(i=1;i<=10;i++)
                        printf("%d\n",i)
                        getch();
                     }
     
       output:-
                      1
                      2
                      3
                      4
                      5
                      6
                      7
                      8
                      9
                      10

a program for do-while loop



               A program for do-while loop

                syntax :-

                                        {
                                      initialization;
                                      do
                                      statements;
                                      incrementation/decrementation;
                                      while(condition);
                                   }
              
               Example :-

                                  #include<stdio.h>
                                  main()
                                  {

                                       int i=10;
                                       do
                                       {
                                           printf("%d\n",i);
                                            i=i+1;
                                                    (or)
                                       i++;
                                        }
     
                                        while(i<=15);
                                         return 0;
                                                 getch();                                 
                                 }
                                                     
             output:-
                           10
                           11
                           12
                           13
                           14
                           15
     


program for while loop


                        Program for while loop 

             syntax :-
                                 while(condition)
                                {
                                    statements;
                                    incrementation/decrementation;
                                 }
 
                 Example  for printing 1 to 10 :-
           
                                #include<stdio.h>
                                main()
                                {
                                   int i=1;
                                   clrscr();
                                   while(i<=10)
                                    printf("%d\n",i++);
                                    getch();
                                 }
                 
                output :-    1
                                  2
                                  3
                                  4
                                  5
                                  6
                                  7
                                  8
                                  9
                                10

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

                          


if-else single statement condition


               if-else single statement condition

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

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

                  Example:-  
                                    #include<stdio.h>
                                    main()
                                   {
                                             clrscr();

                                        printf(3>5 ? "true" : "false");
                                        getch();
                                    }
                         
                                                                                                                                                                                                                                                                                               

              
                    

      output :-

                       

                          

Conditions of the variables


                Conditions of the Variables

           Condition is a comparison between variables.
           Conditions are divided in to 5 types.
          
           * Single statement condition.  // by using symbolic representation.

           * Multiple statements condition. // by using symbolic representation.

                * if-else condition.

          *  nested if-else condition.

          *  ladder if-else condition.

             

Saturday 25 August 2012

Execute the program


                     Execution of program





                 Execution window:-


                       

compile the program


                     Compilation of program

        

compilation window:-
 
 


                

save the program


                     Save the program

             
  saving window:-

    




 

Friday 24 August 2012

start write a program


                     Start write a program

           




                

icon for c


   
         After installation of C, you will find a desktop icon created. 
            Clicking on the TurboC++ icon opens  the below window
                                                                           

           
 
                                                                                   
It is called editing window.Start writing code in the
above window