1. **Write a C program to display “This is my first C Program”.
**
#include <stdio.h>
int main() {
printf("This is my first C Program\n");
return 0;
}
2. **Write a C program to add two numbers (2 and 6) and display its sum.**
#include <stdio.h>
int main() {
int a = 2, b = 6;
int sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}
This is my first C Program
3. **Write a C program to multiply two numbers (4 and 5) and display its product.**
#include <stdio.h>
int main() {
int a = 4, b = 5;
int product = a * b;
printf("Product = %d\n", product);
return 0;
}
4. **Write a C program to calculate area and circumference of a circle. Take user
input
Sum = using
8 scanf().**
#include <stdio.h>
#include <math.h>
int main() {
double r, area, circumference;
printf("Enter radius: ");
scanf("%lf", &r);
area = M_PI * r * r;
circumference = 2 * M_PI * r;
printf("Area = %f\n", area);
printf("Circumference = %f\n", circumference);
return 0;
}
5. **Write a C program to perform addition, subtraction, division and multiplication
of two numbers. Take user input using scanf().**
#include <stdio.h>
int main() {
double a, b;
printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b);
printf("Sum = %f\n", a + b);
printf("Difference = %f\n", a - b);
printf("Product = %f\n", a * b);
printf("Quotient = %f\n", a / b);
return 0;
}
Product = 20
6. **Write C program to evaluate each of the following equations: i) v = u+at ii) s =
ut + 1/2at^2 where v, u, a, t, s are variable.**
#include <stdio.h>
int main() {
double u = 2.0, a = 3.0, t = 4.0;
double v = u + a * t;
double s = u * t + 0.5 * a * t * t;
printf("v = %f\n", v);
printf("s = %f\n", s);
return 0;
}
7. **Find the average of four float numbers and display the result. Take user
input.**
Enter radius: 5
Area = 78.539816
#include <stdio.h>
Circumference = 31.415927
int main() {
float a, b, c, d;
printf("Enter four numbers: ");
scanf("%f %f %f %f", &a, &b, &c, &d);
float avg = (a + b + c + d) / 4;
printf("Average = %f\n", avg);
return 0;
}
8. **Check the difference in the results of the following two operations (in the
same program) where y and m are two integer variables. Print the value of m in
both the cases. a) y=5; m=y++; b) y=7; m=++y;**
#include <stdio.h>
int main() {
int y, m;
y = 5;
m = y++;
printf("Post-increment: m = %d\n", m);
y = 7;
m = ++y;
printf("Pre-increment: m = %d\n", m);
return 0;
}
Enter two numbers: 8 4
Sum = 12.000000
Difference = 4.000000
Product = 32.000000
Quotient = 2.000000