Hello world program in C.
↓
#include <stdio.h>
int main()
{
printf("hello !world.");
return 0;
}
Addition of two number program in C.
↓
#include <stdio.h>
int main()
{
int num1,num2;
printf("Enter the first number:");
scanf("%d",&num1);
printf("Enter the first number:");
scanf("%d",&num2);
printf("Sum is %d",num1+num2);
printf("Subtraction is %d",num1-num2);
printf("Multiplication is %d",num1*num2);
printf("Division is %d",num1/num2);
printf("Rimender is %d",num1%num2);
return 0;
}
Comparision of two user integer input in C.
↓
#include <stdio.h>
int main()
{
int num1,num2;
printf("Enter the first number:");
scanf("%d",&num1);
printf("Enter the first number:");
scanf("%d",&num2);
if(num1>num2) {
printf("%d is greater than %d.",num1,num2);
}
else {
printf("%d is less than %d.",num1,num2);
}
return 0;
}
Even or odd number program in C.
↓
#include <stdio.h>
int main()
{
int num1;
printf("Enter the number to check number is even or odd :");
scanf("%d",&num);
if(num%2==0) {
printf("%d is a even number .",num);
} else {
printf("%d is a odd number .",num);
}
return 0;
}
Factorial number program in C.
↓
#include <stdio.h>
int main()
{
long int num;
int fact=1,i;
printf("Enter the number:");
scanf("%d",&num);
for(i=num;i>0;i--)
{
fact = fact * i;
}
printf("Factorial of %d is %d",num,fact);
return 0;
}
Palindrome number program in C.
↓
#include <stdio.h>
int main()
{
int num,temp,palin=0,re,no;
printf("Enter the number to check number is palindrome or not :");
scanf("%d",&num);
no=num;
while(num>0)
{
re=num%10;
palin=re+(palin*10);
num=num/10;
}
if(no == palin) {
printf("%d is a palindrome number.",no);
}
else {
printf("%d is not a palindrome number.",no);
}
return 0;
}
Armstrong number program in C.
↓
#include <stdio.h>
int main()
{
int no,num,mul=1,sum=0,i,re;
printf("Enter the number to check number is armstrong or not :");
scanf("%d",&num);
no=num;
while(num>0) {
re = num%10;
for(i=0;i<3;i++)
{
mul=mul*re;
}
sum=sum+mul;
num=num/10;
mul=1;
}
if(no == sum) {
printf(" %d is a Armstrong number .",no);
} else {
printf(" %d is not a Armstrong number .",no);
}
return 0;
}
Number reverse program in C.
↓
#include <stdio.h>
int main()
{
int num,no,rev=0,re;
printf("Enter the number to reverse :");
scanf("%d",&num);
while(no>0) {
re=no%10;
rev=re+(rev*10);
no=no/10;
}
printf("Reverse of %d is %d",num,rev);
return 0;
}
Swapping of two number using 3rd variable in C.
↓
#include <stdio.h>
int main()
{
int num1,num2,temp;
printf("Enter the first number:");
scanf("%d",&num1);
printf("Enter the first number:");
scanf("%d",&num2);
temp = num1;
num1 = num2;
num2 = temp;
printf("First number is %d",num1);
printf("Second number is %d",num2);
return 0;
}
Swapping of two number program without using third variable in C.
↓
#include <stdio.h>
int num1,num2;
printf("Enter the first number:");
scanf("%d",&num1);
printf("Enter the first number:");
scanf("%d",&num2);
num1=num1+num2;
num2 = num1-num2;
num1 = num1-num2;
printf("First number is %d",num1);
printf("Second number is %d",num2);
return 0;
Fabonacci Series in C.
↓
#include <stdio.h>
int main()
{
int num1=0,num2=1,fab,range,i;
printf("Enter the range:");
scanf("%d",&range);
printf("\nFabonacci series :");
for(i=0;i<range;i++)
{
printf("%d\t",num1);
num1=num2;
fab=num1+num2;
num2=fab
}
return 0;
}
Program to find average of 3 numbers in C.
↓
#include <stdio.h>
int main()
{
int num1,num2,num3,avg;
printf("Enter the numbers :");
scanf("%d%d%d",&num1,&num2,&num3);
avg = (num1+num2+num3)/3;
printf("Average of numbers is %d",avg);
return 0;
}
Print factors of a number in C.
↓
#include <stdio.h>
int main()
{
int num,i;
printf("Enter the number number:");
scanf("%d",&num);
printf("Factors of %d is :",num);
for(i=1;i<=num;i++)
{
if(num%i==0)
{
printf("%d\t",i);
}
}
return 0;
}
Power of integers in C.
↓
#include <stdio.h>
int main()
{
int res=1,pow,num,i;
printf("Enter the integer number :");
scanf("%d",&num);
printf("Enter the power of number :");
scanf("%d",&pow);
for(i=0;i<pow;i++)
{
res=res*num;
}
printf("Result is %d",res);
return 0;
}
Simple interest(SI) program in C.
↓
#include <stdio.h>
int main()
{
int time,amnt;
float SI,rate,amnt;
printf("Enter the time :");
scanf("%d",&time);
printf("Enter the amount :");
scanf("%f",&amnt);
printf("Enter the percentage :");
scanf("%f",&rate);
SI=(amnt*rate*time)/100;
printf("SI is %f",SI);
return 0;
}
Temperature conversion program in C.
↓
#include <stdio.h>
int main()
{
int ch;
float temp,Fahrenheit,Celsius,Kelvin;
printf(" 1.Celsius to Fahrenheit\n 2.Celsius to kalvin\n 3.Fahrenheit to Celsius\n 4.Fahrenheit to Kalvin\n 5.Kalvin to Celsius\n 6.Kelvin to Fahrenheit\n\n");
printf("Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1 :printf("Enter the temperature :");
scanf("%f",&temp);
Fahrenheit = (temp * 9 / 5) +32;
printf("Temperature in Fahrenheitis %f ",Fahrenheit);
break;
case 2 :printf("Enter the temperature :");
scanf("%f",&temp);
Kelvin = temp + 273.15;
printf("Temperature in Kelvin %f . ",Kelvin);
break;
case 3 :printf("Enter the temperature :");
scanf("%f",&temp);
Celsius = (temp-32)*(5/9);
printf("Temperature in Celsius %f ",Celsius);
break;
case 4 :printf("Enter the temperature :");
scanf("%f",&temp);
Kelvin = ((temp - 32)*(5/9))+273.15;
printf("Temperature in Kelvin %f . ",Kelvin);
break;
case 5:printf("Enter the temperature :");
scanf("%f",&temp);
Celsius = temp - 273.15;
printf("Temperature in Celsius %f ",Celsius);
break;
case 6 :printf("Enter the temperature :");
scanf("%f",&temp);
Fahrenheit = ((temp - 273.15)*(9/5))+32;
printf("Temperature in Fahrenheitis %f ",Fahrenheit);
break;
default : printf("Enter the valid choice :)");
}
return 0;
}
Area of triangle in C.
↓
#include <stdio.h>
int main()
{
float area,h,b;
printf("Enter the height of triangle :");
scanf("%f",&h);
printf("Enter the base of triangle :");
scanf("%f",&b);
area = (h*b)/2;
printf("Area of triangle is %f",area);
return 0;
}
Area of circumference of circle in C.
↓
#include <stdio.h>
int main()
{
float cir,radius;
printf("Enter the radius of a circlre :");
scanf("%f",&radius);
cir = 2*3.14*radius;
printf("Area of circumference of circle is %f",cir);
return 0;
}
Area of Square in C.
↓
#include <stdio.h>
int main()
{
float a;
printf("Enter the edge size :");
scanf("%f",&a);
printf("Area is %f:",a*a);
return 0;
}
Area of Circle in C.
↓
#include <stdio.h>
int main()
{
float rad,area;
printf("Enter the size of radius :");
scanf("%f",&rad);
area=3.14*rad*rad;
printf("Area is %f:",area);
return 0;
}
© Copyright 2021 . All rights Reserved.