1. Write a Program to print a message "Hello World"
#include<stdio.h>
int main()
{
printf("Hello World"); /* to print the statement */
return 0;
}
https://www.ankitweblogic.com/c/first-c-program.php
Ankitweblogic
Hello World | C Program
How to print 'Hello World' using C-Language in Turbo C++ IDE, with code explanation. Full form of stdio, conio, shortcut key to compile and run program, meaning of & in scanf and getch
2. WAP to Input 2 numbers and find the sum.
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter 1st Number: ");
scanf("%d",&a);
printf("Enter 2nd Number: ");
scanf("%d",&b);
c=a+b;
printf("Sum = %d",c);
return 0;
}
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter 1st Number: ");
scanf("%d",&a);
printf("Enter 2nd Number: ");
scanf("%d",&b);
c=a+b;
printf("Sum = %d",c);
return 0;
}
3. WAP to input two numbers and find multiplication
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter 1st number");
scanf("%d",&a);
printf("Enter 2nd number");
scanf("%d",&b);
c=a*b;
printf("Multiplication = %d",c);
return 0;
}
4. WAP to Input number and calculate its square and cube.
#include<stdio.h>
int main()
{
int n, sq, cube;
printf("Enter Number:");
scanf("%d",&n);
sq = n * n;
cube = n * n * n;
printf("Square = %d",sq);
printf("Cube = %d",cube);
return 0;
}
5. WAP to input radius and calculate area of circle and circumference of a circle. Area of circle = 3.14*r*r, Circumference of circle = 2*3.14*r.
#include<stdio.h>
int main()
{
float r, a, c;
printf("Enter radius:");
scanf("%f", &r);
a=3.14*r*r;
printf("Area of circle = %f\n", a);
c = 2*3.14*r;
printf("Circumference of circle = %f\n", c);
return 0;
}
6. WAP to input length and breadth of a rectangle and calculate its area. Area=Length*Breadth.
#include<stdio.h>
int main()
{
int a, l, b;
printf("Enter length:");
scanf("%d",&l);
printf("Enter breadth:");
scanf("%d",&b);
a=l*b;
printf("Area = %d",a);
return 0;
}
7. WAP to input radius and height of a cylinder and calculate volume of cylinder. Volume=3.14*r*r*h
#include<stdio.h>
int main()
{
float r, h, v;
printf("Enter Radius of a Cylinder:");
scanf("%f",&r);
printf("Enter Height of a Cylinder:");
scanf("%f",&h);
v = 3.14 * r * r * h;
printf("Volume of Cylinder = %f",v);
return 0;
}
8⃣ WAP to input principal, rate, time and calculate Simple Interest. Simple Interest=Principal*Rate*Time/100.
#include<stdio.h>
int main()
{
float p,r,t,si;
printf("Enter Principal, Rate, Time: ");
scanf("%f%f%f",&p,&r,&t);
si = p*r*t/100;
printf("Simple Interest = %f",si);
return 0;
}
9⃣ WAP to Input 5 subject marks of a student and find total marks and percentage obtained by the student.
#include<stdio.h>
int main()
{
int eng, hindi, maths, sci, computer, total;
float per;
printf("Enter English marks:");
scanf("%d",&eng);
printf("Enter Hindi marks:");
scanf("%d",&hindi);
printf("Enter Maths marks:");
scanf("%d",&maths);
printf("Enter Science marks:");
scanf("%d",&sci);
printf("Enter Computer marks:");
scanf("%d",&computer);
total = eng + hindi + maths + sci + computer;
per=total/5.0;
printf("Total = %d",total);
printf("\nPercentage = %f",per);
return 0;
}
🔟 WAP to convert temperature from Fahrenheit to Celsius. c=(f-32)*5/9
#include<stdio.h>
int main()
{
float c, f;
printf("Enter temperature in Fahrenheit: ");
scanf("%f",&f);
c=(f-32)*5/9;
printf("Temperature in Celsius = %.2f",c);
return 0;
}
#include<stdio.h>
int main()
{
float c, f;
printf("Enter temperature in Fahrenheit: ");
scanf("%f",&f);
c=(f-32)*5/9;
printf("Temperature in Celsius = %.2f",c);
return 0;
}
Output
Enter temperature in Fahrenheit: 98.6
Temperature in Celsius = 37.00
1⃣1⃣ WAP to convert temperature from Celsius to Fahrenheit. f=c*9/5+32
#include<stdio.h>
int main()
{
float c, f;
printf("Enter temperature in Celicus:");
scanf("%f",&c);
f=c*9/5+32;
printf("Temperature in Fahrenheit = %.2f",f);
return 0;
}
#include<stdio.h>
int main()
{
float c, f;
printf("Enter temperature in Celicus:");
scanf("%f",&c);
f=c*9/5+32;
printf("Temperature in Fahrenheit = %.2f",f);
return 0;
}
Output
Enter temperature in Celicus: 37
Temperature in Fahrenheit = 98.60
👍1
12 WAP to Input two numbers and swap them.
#include<stdio.h>
int main()
{
int a, b, c;
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("A = %d\n",a);
printf("B = %d",b);
return 0;
}
#include<stdio.h>
int main()
{
int a, b, c;
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("A = %d\n",a);
printf("B = %d",b);
return 0;
}
Output:
Enter two numbers: 10
20
A = 20
B = 10
13 WAP to Input two numbers and swap them without using 3rd variable.
#include<stdio.h>
int main()
{
int a, b, c;
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
b=a+b;
a=b-a;
b=b-a;
printf("A = %d\n",a);
printf("B = %d",b);
return 0;
}
#include<stdio.h>
int main()
{
int a, b, c;
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
b=a+b;
a=b-a;
b=b-a;
printf("A = %d\n",a);
printf("B = %d",b);
return 0;
}
Output:
Enter two numbers: 10
20
A = 20
B = 10