C program to swap two numbers

#include< stdio.h >
 #include< conio.h >
 void main ()
{
 int p, q, swap;
 clrscr();
 printf("Enter two numbers:");
 scanf("%d\t %d",&a,&b);
 swap=p; p=q; q=swap;
 printf("After swapping the values are p=%d and q=%d",p,q);
 getch();
 }
 }

OUTPUT :

Enter two numbers :5 8
After swapping the values are p=8 and q=5

C program to calculate the square of a number

# include< stdio.h >
# include< conio.h >
void main ()
{
          int x, y;
          clrscr();
          printf(" Enter a number : ");
          scanf("%d",&x);
          y=x*x ;
          printf(" The square of %d is %d",x,y);
          getch();
}

OUTPUT :

Enter a number : 5
The square of 5 is 25

C program to display reverse of a number

#include< stdio.h >
#include< conio.h >
void main ()
{
           int n , d1, d2;
           clrscr();
           printf(" Enter a number : ");
           scanf("%d",&n);
           d1=n%10 ;
            n=n/10 ;
           d2=n%10 ;
           printf("Reversed no is %d%d",d1,d2);
           getch();
}

OUTPUT :

Enter a number :25
Reversed no is 52

C program to calculate area and perimeter of a rectangle with given parameters

# include< stdio.h >
# include< conio.h >
void main ()
{
           float l, b, a, peri;
           clrscr();
           printf(" Enter the length and breadth of the rectangle : ");
           scanf("\n%f\n%f",&l,&b);
           a = l * b;
           peri = 2* (l + b);
           printf(" The area of rectangle is= %f and its perimeter is = %f",a, peri);
           getch();
}

OUTPUT :

Enter the length and breadth of the rectangle :
5
4
The area of rectangle is= 20 and its perimeter is = 18

C program to calculate the product of two number

#include< stdio.h >
#include< conio.h >
void main ()
{
         int x, y, z;
         clrscr();
         printf(" Enter two numbers : ");
         scanf("\n%d\n%d",&x,&y);
         z=x*y ;
         printf(" The product of given numbers is %d",z);
        getch();
}

OUTPUT :

Enter two numbers :
5
4
The product of given numbers is 20

C program to find whether the given number is prime number or not

#include< stdio.h >
#include< conio.h >
void main()
{
          int i=2,num;
         clrscr();
          printf("Enter a number:");
         scanf("%d",&num);
         while(num%i!=0)
         {
                      i++;
          }
           if(num==i)
          {
                      printf("The number %d is a prime Number",num);
          }
          else
          {
                    printf("The number %d is not a prime number",num);
          }
          getch();
}

OUTPUT :

Enter a number :13
The number 13 is a prime Number

OR

OUTPUT :

Enter a number :12
The number 12 is not a prime Number

C program to display the month name

#include< stdio.h >
#include< conio.h >
void main()
{
          int month;
          clrscr();
          printf("Enter a month number:");
          scanf("%d",&month);
         switch(month)
        {
                    case 1:printf("January");
                    break;
                    case 2:printf("February");
                    break;
                    case 3:printf("March");
                    break;
                    case 4:printf("April");
                    break;
                    case 5:printf("May");
                    break;
                    case 6:printf("June");
                    break;
                    case 7:printf("July");
                    break;
                    case 8:printf("August");
                    break;
                    case 9:printf("September");
                    break;
                    case 10:printf("October");
                    break;
                    case 11:printf("November");
                    break;
                   case 12: printf("December");
                   break;
                  default:printf("Invalid month number");
        }
        getch();
}

OUTPUT :

Enter a month number :12
December

OR

OUTPUT :

Enter a month number :15
Invalid month number

C program to find the lcm of two numbers

#include< stdio.h >
#include< conio.h >
void main()
{
           int num1,num2,lcm;
           clrscr();
           printf("Enter two numbers:");
           scanf("%d\t %d",&num1,&num2);
          if (num1>num2)
                    lcm=num1;
         else
                    lcm=num2;
         while(lcm%num1!=0 || lcm%num2!=0)
         {
                    lcm++;
         }
         printf("LCM= %d",lcm);
        getch();
}

OUTPUT :

Enter two numbers: 2 4
LCM=2

Write a simple c program to display hello friends

# include< stdio.h >
# include< conio.h >
void main ()
{
                  printf("Hello Friends");
                  getch();
}

OUTPUT :

Hello Friends

C program to find GCD and LCM of given numbers

#include< stdio.h >
#include< conio.h >
void main()
{
          int n1,n2,lcm,gcd;
          clrscr();
          printf("Enter two numbers:");
          scanf("%d %d",&n1,&n2);
          if (n1>n2)
         {
               lcm=n1;
               gcd=n2;
         }
        else
       {
               lcm=n2;
               gcd=n1;
        }
        while(lcm%n1!=0 || lcm%n2!=0)
        {
                lcm++;
        }
        while(n1%gcd!=0 || n2%gcd!=0)
       {
                gcd--;
        }
        printf("LCM= %d \nGCD=%d",lcm,gcd);
        getch();
}

OUTPUT :

Enter a month number :12
December

OR

OUTPUT :

Enter a month number :15
Invalid month number

C program to find Multiplication table of a number

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

OUTPUT :

Enter a number :
2 X 1 = 2
2 X 2 = 4
2 X 3 = 6
2 X 4 = 8
2 X 5 = 10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 = 20

C program to find sum of n numbers using recursion

#include< stdio.h >
#include< conio.h >
void main()
{
         int n,sum;
         int recursion (int n);
         clrscr();
         printf("Enter a number:");
         scanf("%d",&n);
         S=recursion(n);
         printf("Sum of numbers from 1 to %d is %d",n,S);
         getch();
}
int recursion (int n)
{
        if(n==1)
                 return 1;
        else
                 return (n + recursion (n-1));
}

OUTPUT :

Enter a number : 5
Sum of numbers from 1 to 5 is 15

C program to find whether the given number is Armstrong or not : (e.g: 153= 1ᶾ + 5ᶾ + 3ᶾ = 153 )

#include< stdio.h >
#include< conio.h >
void main()
{
          int sum=0,digit,n,temp;
         clrscr();
         printf("Enter a number:");
         scanf("%d",&n);
         temp=n;
         while(n!=0)
         {
                digit=n%10;
                sum=sum+digit*digit*digit;
                n=n/10;
         }
         if(sum==temp)
        {
                printf("The number %d is an Armstrong Number",n);
        }
        else
        {
               printf("The number %d is not an Armstrong Number",n);
        }
        getch();
}

OUTPUT :

Enter a number :153
The number 153 is an Armstrong Number

OR

OUTPUT :

Enter a number :152
The number 152 is not an Armstrong Number

C program to calculate the average of three numbers

#include< stdio.h >
#include< conio.h >
void main ()
{
          int a, b, c, S;
          float Avg;
          clrscr();
          printf("Enter three numbers:");
          scanf("%d\t %d\t %d",&a,&b,&c);
          S= a+b+c ;
         Avg=S/3.0 ;
         printf(" The average of given numbers is equal to :%f",Avg);
         getch();
}

OUTPUT :

Enter three numbers :2 5 8

The average of given numbers is equal to :5