Learn C Programming Language Tutorial
1. Write a Program to print any message
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“Hello Word”);
printf(“\n My Name is Gyancs”);
getch();
}
2. Write a Program to print sum of two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter The Two Number :-“);
scanf(“%d %d”,&a,&b);
c=a+b;
printf(“\n Sum of the Number is %d”,c);
getch();
}
3. Write a Program for multiply of two numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter The Two Number :-“);
scanf(“%d %d”,&a,&b);
c=a*b;
printf(“\n Multiply of the Number is %d”,c);
getch();
}
4. Write a Program to enter the temperature in Celsius(c) then count it into Fahrenheit.
#include<stdio.h>
#include<conio.h>
void main()
{
int c;
float f;
clrscr();
printf(“Enter Any Temperature in Celsius :”);
scanf(“%d”,&c);
f=(c*9/5)+32;
printf(“\n Temperature in Fahrenheit=%.2f”,f);
getch();
}
5. Write a Program to swap the number taking the help of third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf(“Enter Two Number :”);
scanf(“%d%d”,&a,&b);
temp=a;
a=b;
b=temp;
printf(“\nSwap Value of a=%d “,a);
printf(“\nSwap Value of b=%d “,b);
getch();
}
6. Write a Program to calculate the volume of box.
#include<stdio.h>
#include<conio.h>
void main()
{
int l,h,b,volume;
clrscr();
printf(“Enter Three Number :”);
scanf(“%d%d%d”,&l,&b,&h);
volume=l*b*h;
printf(“\nVolume of box=%d “,volume);
getch();
}
7. Write a Program to swap the number without taking the help of third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“Enter Two Number :”);
scanf(“%d%d”,&a,&b);
a=b-a;
b=b-a;
a=b+a;
printf(“\nSwap Value of a=%d “,a);
printf(“\nSwap Value of b=%d “,b);
getch();
}
8. Write a Program to add five number first two 1 three value is integer and last two value is float.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
float d,e,add;
clrscr();
printf(“Enter Five Number :”);
scanf(“%d%d%d%f%f”,&a,&b,&c,&d,&e);
add=a+b+c+d+e;
printf(“\nAddition=%.2f “,add);
getch();
}
9. Write a Program to check a year is leap year not.
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf(“Enter any Year :”);
scanf(“%d”,&year);
if(year%4==0)
{
printf(“\nYear is Leap Year”);
}
else
{
printf(“\nYear is not Lear Year”);
}
getch();
}
10.Write a Program to print number is even or odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&a);
if(a%2==0)
{
printf(“\Number is Even”);
}
else
{
printf(“\nNumber is Odd”);
}
getch();
}
11. Write a Program to print the no is positive or negative.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&a);
if(a>0)
{
printf(“\Number is Positive”);
}
else
{
printf(“\nNumber is Negative”);
}
getch();
}
12. Write a Program in C to find the greater number enter by user.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“Enter any Number :”);
scanf(“%d%d”,&a,&b);
if(a>b)
{
printf(“\n A is grater”);
}
else
{
printf(“\n B is grater”);
}
getch();
}
13. Write a Program in C to find the greater number Input 3 No.
#include<stdio.h>
#include<conio.h>
void main ()
{
int a,r,l;
clrscr();
printf(“Enter The three No.”);
scanf(“%d %d %d”,&a,&r,&l);
if ((a>r) && (a>l))
{
printf(“A is greater than”);
}
else if((r>a) && (r>l))
{
printf(“R is greater than”);
}
else
{
printf(“L is greater than”);
}
getch();
}
Or
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
clrscr();
printf(“Enter the values of A, B and C\n“);
scanf(“%d %d %d“, &a, &b, &c);
printf(“A=%d B=%d C=%d\n“, a, b, c);
if (a > b)
{
if (a > c)
{
printf(“A is the Greatest Number \n“);
}
else
{
printf(“C is the Greatest Number \n“);
}
}
else if (b > c)
printf(“B is the Greatest Number \n“);
else
printf(“C is the Greatest Number \n“);
getch();
}
14. Write a Program to enter any no and check whether the given no is palindrome or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a=0,c=0,r=0;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&n);
r=n;
while(n>0)
{
a=n%10;
c=(c*10)+a;
n=n/10;
}
if(r==c)
{
printf(“\n Given No. is Palindrome”);
}
else
{
printf(“\n Given No. is not Palindrome”);
}
getch();
}
15. Write a Program to enter any no. and check whether the given no. is Armstrong or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a=0,c=0,k=0;
clrscr();
printf(“Enter any Number :”);
scanf(“%d“,&n);
k=n;
while(n>0)
{
a=n%10;
c=c+(a*a*a);
n=n/10;
}
if(k==c)
{
printf(“\n Given No. is Armstrong”);
}
else
{
printf(“\n Given No. is not Armstrong”);
}
getch();
}
16. Write a Program to find the factorial of given no.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fact;
clrscr();
printf(“Enter any Digit:”);
scanf(“%d“,&num);
fact=1;
do
{
fact=fact*num;
num–;
}
while(num>=1);
printf(“\n The Factorial of the given No. is=%d”,fact);
getch();
}
17.Write a Program to Print
*
* *
* * *
* * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,y;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&n);
for(x=1;x<=n;x++)
{
for(y=1;y<=x;y++)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
18.Write a Program to Print
* * * *
* * *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
clrscr();
printf(“Enter any Limit :”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf(” “);
}
for(k=n;k>=i;k–)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
19.Write a Program to Print
*
* *
* * *
* * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
clrscr();
printf(“Enter any Limit :”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=i;j<=n-1;j++)
{
printf(” “);
}
for(k=1;k<=i;k++)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
20. Write a program to Print
*
* * *
* * * * *
* * *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
clrscr();
printf(“Enter any Limit :”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(” “);
}
for(k=1;k<=i*2-1;k++)
{
printf(“*”);
}
printf(“\n”);
}
for(i=n-1;i>=1;i–)
{
for(j=n;j>i;j–)
{
printf(” “);
}
for(k=1;k<=i*2-1;k++)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
21.Write a Program to Print
* * * *
* * *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,y;
clrscr();
printf(“Enter any Limit :”);
scanf(“%d”,&n);
for(x=n;x>=1;x–)
{
for(y=1;y<=x;y++)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
22.Write a Program to Print
*
* * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,x,y,n;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&n);
for(x=n;x>=1;x–)
{
for(y=1;y<=x-1;y++)
{
printf(” “);
}
for(y=1;y<=a;y++)
{
printf(“*”);
}
printf(“\n”);
a=a+2;
}
getch();
}
23.Write a Program to Print
* * * * *
* * *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,y;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&n);
for(x=n;x>=1;x–)
{
for(y=1;y<=(n-x);y++)
{
printf(” “);
}
for(y=1;y<=(2*x-1);y++)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}
24.Write a Program to Print
1 2 3 4
1 2 3
1 2
1
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,y;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&n);
for(x=n;x>=1;x–)
{
for(y=1;y<=x;y++)
{
printf(“%d “,y);
}
printf(“\n”);
}
getch();
}
25. Write a Program to Print
1
1 2
1 2 3
1 2 3 4
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,y;
clrscr();
printf(“Enter any Number :”);
scanf(“%d”,&n);
for(x=1;x<=n;x++)
{
for(y=1;y<=x;y++)
{
printf(“%d “,y);
}
printf(“\n”);
}
getch();
}
sir ji mujhe c language aur Python sikhni hai
Contact
Mr.Mohd Ishaque
Mob.7007558778
He is best teacher