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();
}

    
 

Program to print first 10 multiples of an integer.

#include<stdio.h>
#include<conio.h>
void main()
{
                int n,i;
                clrscr();
                printf("\n Enter a integer number");
                scanf("%d",&n);
                for(i=1;i<=10;i++)
                {
                               printf("\n %d * %d = %d ",n,i,n*i);
                 }
                 getch();
}

Program to calculate the factorial of a number.

#include<stdio.h>
#include<conio.h>
void main()
{
                int n,i=1,fact=1;
                clrscr();
                printf("\n Enter  a number ");
                scanf("%d",&n);
                while(i<=n)
                {
                                fact=fact * i;
                                i++;
                 }
                 printf("\n Factorial of  %d = %d",n,fact);
                 getch();
}


NOTE :=  Factorial of a number can be calculated  as
                  5! = 5 * 4 * 3 * 2 * 1 = 120.

Program to display digits 1 to n.

#include<stdio.h>
#include<conio.h>
void main()
{
                  int n, i=1;
                  clrscr();
                  printf("\n Enter the last digit");
                  scanf("%d",&n);
                  while(i<=n)
                  {
                                  printf("\n %d",i);
                                  i++;
                  }
                  getch();
}