Search Your C Program

Tuesday, 7 February 2012

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

Monday, 30 January 2012

Program to perform basic arithmatic operation using switch statement

#include<stdio.h>
#include,conio.h>
void main()

                 int a,b,c,choice;
                 clrscr();
                 printf("\n Enter two numbers");
                 scanf(" %d %d ", &a, &b);
                 printf("\n Press 1 for Addition ");
                 printf("\n Press 2 for Subtraction ");
                 printf("\n Press 3 for Multiplication ");
                 printf("\n Press 4 for Division ");
                 printf("\n Enter your choice");
                 scanf(" %d", &choice);
                 switch(choice)
                 {
                                       case 1:
                                       c=a+b;
                                       printf("\n Sum = %d",c);
                                       break;
                                      
                                       case 2:
                                       c=a-b;
                                       printf("\n Subtraction = %d",c);
                                       break;

                                       case 3:
                                       c=a*b;
                                       printf("\n Multiplication = %d",c);
                                       break;

                                       case 4:
                                       c=a/b;
                                       printf("\n Division = %d",c);
                                       break;
                
                                       default :
                                       printf("\n Wrong Input");
                }
                getch();