![]() |
Top 10 simplest programs of C language |
1. Write a program to Print "hello world".
#include<stdio.h>int main(){printf("Hello world!");return 0;}
Result:- Hello world!
2. Write a program to add two Numbers from the user.
#include<stdio.h>int main(){int a,b,sum;printf("Enter first number:\n ");scanf("%d",&a);printf("Enter second number:\n ");scanf("%d",&b);printf("\n\n");sum=a+b;printf("sum of %d and %d :\n %d ",a,b,sum);return 0;}
Result:- Enter first number: 5
Enter second number: 6
sum of 5 and 6. 11
3. Write a program to take input from user and find remainder and quotient.
#include<stdio.h>int main(){int a,b,quotient,remainder;printf("Enter Dividend:\n");scanf("%d",&a);printf("Enter Divisor:\n");scanf("%d",&b);quotient=a/b;remainder= a % b;printf("\n\n");printf("the quotient of %d divided by %d is %d \n ",a,b,quotient);printf("\n and the remainder is:%d \n\n",remainder);return 0;}
Result:- Enter Dividend: 6
Enter Divisor: 2
the quotient of 6 divided by 2 is 3 and the remainder is:0
4.Write a program to convert Celsius to Fahrenheit.
#include<stdio.h>int main(){float c,f;printf("Enter Celsius: ");scanf("%f",&c);f = (c*9/5)+ 32;printf("fahrenheit : %f",f);return 0;}
Result:- Enter Celsius: 36
Fahrenheit : 96.800003
5. Write a program to find simple interest.
#include<stdio.h>int main(){ float P,R,T,SI,Am;printf("Enter Principal Value: ");scanf("%f",&P);printf("Enter Rate: ");scanf("%f",&R);printf("Enter Time: ");scanf("%f",&T);SI = P*R*T/100;printf("Simpal intrest: %f\n\n", SI);Am=P+SI;printf("full amount:%f",Am);return 0;}
Result:- Enter Principal Value: 500
Enter Rate: 6
Enter Time: 5
Simple interest: 150.000000
full amount:650.000000
6. Write a program to find area of triangle.
#include<stdio.h>int main(){float Ar,b,h;printf("Enter base:\n ");scanf("%f",&b);printf("Enter height:\n ");scanf("%f",&h);Ar= b*h/2;printf("area of triangle is:\n %f", Ar);return 0;}
Result:- Enter base: 6
Enter height: 7
area of triangle is: 21.000000
7. Write a program to check Even or odd number.
#include<stdio.h>int main(){ int a;printf("Enter a number:\n");scanf("%d",&a);if(a%2==0)printf("Number is Even");elseprintf("Number is odd");return 0;}
Result:- Enter a number: 5
Number is odd
8. Write a program to find greater in two numbers.
#include<stdio.h>int main(){int a, b;printf("Enter first number:\n");scanf("%d",&a);printf("Enter second number:\n");scanf("%d",&b);if(a<b)printf("Second is greater");elseprintf("first is greater");return 0;}
Result :- Enter first number: 5
Enter second number: 8
First is greater
9. Write a program to check positive and negative number.
#include<stdio.h>int main(){int a;printf("Enter a number\n");scanf("%d",&a);if(a<0)printf("%d is negative number",a);elseprintf("%d is positive number",a);return 0;}
Result:- Enter a number: -9
-9 is negative number
10. Write a program to check leap year.
#include<stdio.h>int main(){ int a;printf("Enter a year: \n");scanf("%d",&a);printf("\n");if((a%4==0&&a%100!=0)||a%400==0)printf("year %d is a leap year", a);else printf("year %d is not a leap year",a);return 0;}
Result:- Enter a year: 2025
year 2025 is not a leap year