Search Your C Program

Sunday 12 February 2012

Program to print the n terms of fibonacci series.

#include<stdio.h>
#include<conio.h>
void main()
{
                int a,b,c,i,n;
                a=0;
                b=1;
                clrscr();
                printf("\n Enter the number of terms");
                scanf("%d", &n);
                if(n == 1)
                          printf("\n  %d  ",a);
                else if(n>=2)
                {
                                  printf("\n  %d  \t  %d ",a,b);
                                  for(i=3;i<=n;i++)
                                  {
                                                    c=a+b;
                                                    printf("\t  %d",c);
                                                    a=b;
                                                    b=c;
                                   }
                 }
             
                 getch();
 }

Thursday 9 February 2012

Program to find whether a number is palindrome or not.

#include<stdio.h>
#include<conio.h>
void main()
{
                long rev = 0,n, num , rem;
                clrscr();
                printf("\n Enter the number");
                scanf("%ld",&num);
                n=num;
                while(n>0)
                {
                              rem= n % 10;
                              n=n/10; 
                              rev=rev*10 + rem;
                }
                
                if(rev = = num)
                             printf(" \n Number %ld is palindrome", num);
                else
                             printf(" \n Number %ld is not palindrome", num);                    
                getch();
}               

Program to reverse a number.

#include<stdio.h>
#include<conio.h>
void main()
{
                long rev = 0, rem , n;
                clrscr();
                printf("\n Enter the number ");
                scanf("%ld",&n);
                while(n>0)
                {
                                 rem=n%10;
                                 n=n/10;  
                                 rev=rev*10 +rem;
                }
                printf("\n The reverse number = %ld",rev);
 }

Tuesday 7 February 2012

Program to calculate the average of given n number.

#include<stdio.h>
#include<conio.h>
void main()
{
               int i,n,sum=0,x;
               float avg;
               printf("\n How many numbers ");
               scanf(" %d ",&n);
               for(i=1;i<=n;i++)
               {
                               printf("\n Eneter %d number ",i);
                               scanf("%d",&x);
                               sum = sum + x;
                }
               
                avg=sum/n;
                printf("\n The average of numbers = %f",avg);
                getch();
}