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 display a pattern

1
1 2
1 2 3
1 2 3 4

#include< stdio.h >
#include< conio.h >
void main()
{
           int n;
           void pattern(int n);
           clrscr();
           printf("Enter the number of lines:");
           scanf("%d",&n);
           pattern(n);
           getch();
}
void pattern(int n)
{
          int i,j;
          for(i=1;i<=n;i++)
         {
                for(j=1;j<=i;j++)
               {
                       printf("%d",j);
               }
               printf("\n");
        }
}

OUTPUT :

Enter the number of lines :4
1
1 2
1 2 3
1 2 3 4

C program to display a pattern

*
* *
* * *
* * * *

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

OUTPUT :

Enter the number of lines :4
*
* *
* * *
* * * *

C program to find ᵑPᵣ of a number

#include< stdio.h >
#include< conio.h >
void main()
{
          int n,r,npr;
          int fact (int num);
          clrscr();
          printf("Enter the values of n and r:");
          scanf("\t%d\t %d",&n,&r);
          npr=fact(n)/fact(n-r);
          printf("nPr=%d",npr);
          getch();
}
int fact (int num)
{
         int i,a=1;
         for(i=1;i<=num;i++)
        {
                  a=a*i;
        }
        return a;
}

OUTPUT :

Enter the values of n and r:3 2
nPr =6

C program to find ᵑCᵣ of a number

#include< stdio.h >
#include< conio.h >
void main()
{
          int n,r,ncr;
          int fact (int num);
          clrscr();
          printf("Enter the values of n and r:");
          scanf("\t%d\t %d",&n,&r);
          ncr=fact(n)/(fact(r)*fact(n-r));
          printf("nCr =%d",ncr);
          getch();
}
int fact (int num)
{
         int i,a=1;
         for(i=1;i<=num;i++)
        {
                    a=a*i;
        }
        return a;
}

OUTPUT :

Enter the values of n and r:3 2
nCr =3

C program to find Fibonacci series using recursion:


#include< stdio.h >
#include< conio.h >
void main()
{
          int num,i;
          int fibo (int ,int ,int);
          clrscr();
          printf("Enter the number of elements:");
          scanf("%d",&num);
          printf("0\n");
          for(i=1;i<=num-1;i++)
         {
                  printf("%d\n",fibo(0,1,i));
         }
         getch();
}
int fibo (int a, int b, int i)
{
         if(i==1)
         return b;
        else
        return (fibo(b,a+b,--i));
}

OUTPUT :

Enter the number of elements:4
0
1
1
2

C program to find Fibonacci series :



#include< stdio.h >
#include< conio.h >
void main()
{
          int n;
          void fibo(int n);
          clrscr();
          printf("Enter a number: ");
          scanf("%d",&n);
          printf("Fibonacci Series\n0\n1\n");
          fibo(n);
          getch();
}
void fibo(int n)
{
         int a=0,b=1,c,i;
         for(i=1;i<=n-2;i++)
        {
              c=a+b;
              printf("%d\n",c);
              a=b;
              b=c;
        }
}

OUTPUT :

Enter a number:4
0
1
1
2

C program to find factorial of a number using recursion :


#include< stdio.h >
#include< conio.h >
void main()
{
          int num,factorial;
          int fact (int num);
          clrscr();
          printf("Enter a number:");
          scanf("%d",&num);
          factorial=fact(num);
          printf("Factorial=%d",factorial);
          getch();
}
int fact (int num)
{
         if(num==1)
         return 1;
         else
         return (num * fact (num-1));
}

OUTPUT :

Enter a number : 5
Factorial=120

C program to find factorial of a number :



#include< stdio.h >
#include< conio.h >
void main()
{
          int num,facto;
          int fact (int num);
          clrscr();
          printf("Enter a number:");
          scanf("%d",&num);
          facto=fact(num);
          printf("Factorial=%d",facto);
          getch();
}
int fact (int num)
{
          int i,a=1;
          for(i=1;i<=num;i++)
         {
                    a=a*i;
         }
         return a;
}

OUTPUT :

Enter a number:3
Factorial=6
C program to find xᵑ using recursion :

#include< stdio.h >
#include< conio.h >
void main()
{
          int n,x,y;
          int expo (int x, int n);
          clrscr();
          printf("Enter the values of x and n:");
          scanf("\t%d \t%d",&x,&n);
          y=expo(x,n);
          printf("The value of x raise to n is %d",y);
         getch();
}
int expo (int x, int n)
{
         if(n==1)
         return x;
         else
         return (x*expo(x,n-1));
}

OUTPUT :

Enter the values of x and n:2 3
The value of x raise to n is 8

C program to find average of three numbers :

#include< stdio.h >
#include< conio.h >
void main()
{
           int num1,num2,num3;
           void avg (int a, int b, int c);
           clrscr();
           printf("Enter three numbers:");
           scanf("\n%d \n%d\n %d",&num1,&num2,&num3);
           avg(num1,num2,num3);
           getch();
}
void avg (int a, int b, int c)
{
          float avgg;
         avg=(a+b+c)/3.0;
         printf("Average of given numbers is=%f",avgg);
}

OUTPUT :

Enter three numbers:
5
8
6
Average of given numbers is=19
C program to add two numbers :

#include< stdio.h >
#include< conio.h >
void main()
{
          int num1,num2;
          void add (int a, int b);
          clrscr();
          printf("Enter two numbers:");
          scanf("%d %d",&num1,&num2);
          add(num1,num2);
          getch();
}
void add (int a, int b)
{
          int c;
          c=a+b;
          printf("Sum of given numbers is=%d",c);
}

OUTPUT :

Enter two numbers:
5
8
Sum of given numbers=13
C program to add two numbers :

#include< stdio.h >
#include< conio.h >
void main()
{
          int num1,num2,S;
          int add (int a, int b);
          clrscr();
          printf("Enter two numbers:");
          scanf("\n%d\n %d",&num1,&num2);
          S=add(num1,num2);
          printf("Sum of given numbers=%d",S);
         getch();
}
int add (int a, int b)
{
         int c;
        c=a+b;
       return c;
}

OUTPUT :

Enter two numbers:
5
8
Sum of given numbers=13

C program to find whether the given number is even or odd

#include< stdio.h >
#include< conio.h >
void main ()
{
          int n, rem;
         clrscr();
         printf("Enter a number:");
         scanf("%d",&n);
         rem=n%2;
         if (rem==0)
        printf("The given number is Even ")
        else
        printf("The given number is Odd ");
        getch();
}

OUTPUT :

Enter a number :5
The given number is Odd

OR

OUTPUT :
Enter a number :4
The given number is Even

C program to find whether the given number is divisible by 10 or not

#include< stdio.h >
#include< conio.h >
void main()
{
          int num;
          clrscr();
          printf("Enter a number:");
          scanf("%d",&num);
          if(num%10==0)
         {
                   printf("The number is divisible by 10");
         }
         else
        {
                   printf("The number is not divisible by 10");
         }
         getch();
}

OUTPUT :

Enter a number :60
The number is divisible by 10

OR

OUTPUT :

Enter a number :65
The number is not divisible by 10

C program to display digits separately

#include< stdio.h >
#include< conio.h >
void main ()
{
          int n1, n2, num;
         clrscr();
         printf("Enter a two digit number:");
         scanf("\t%d",&num);
         n2 = num%10;
         num = num / 10;
         n1 = num%10;
        printf(" The digits are :\n%d\n%d",n1,n2);
        getch();
}

OUTPUT :

Enter a two digit number: 25
The digits are :
2
5

C program to calculate the area of circle from given radius

#include< stdio.h >
#include< conio.h >
void main ()
{
           float radius, area;
          clrscr();
          printf(" Enter the value of radius for a circle : ");
          scanf("%f",&radius);
          area = 3.14 *radius*radius;
          printf("The area of circle is equal to :\t%f",area);
          getch();
}

OUTPUT : 

Enter the value of radius for a circle : 5
The area of circle is equal to : 78.5