0% found this document useful (0 votes)
27 views8 pages

Sequential Programs Solutions

The document contains a series of C programming examples that demonstrate basic programming concepts such as input/output, arithmetic operations, and calculations for various mathematical and physical properties. Each example includes a brief description of its function, such as printing messages, performing calculations, and converting units. The examples cover a wide range of topics, from simple tasks like printing text to more complex calculations like compound interest and volume of geometric shapes.

Uploaded by

ranjitasah02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views8 pages

Sequential Programs Solutions

The document contains a series of C programming examples that demonstrate basic programming concepts such as input/output, arithmetic operations, and calculations for various mathematical and physical properties. Each example includes a brief description of its function, such as printing messages, performing calculations, and converting units. The examples cover a wide range of topics, from simple tasks like printing text to more complex calculations like compound interest and volume of geometric shapes.

Uploaded by

ranjitasah02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// 1. Print "Hello, World!

"
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}

// 2. Print Your Name


#include <stdio.h>
int main() {
printf("My name is Chintu Bimaar.\
n");
return 0;
}

// 3. Add Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Sum: %d\n", a + b);
return 0;
}

// 4. Subtract Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Difference: %d\n", a - b);
return 0;
}

// 5. Multiply Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Product: %d\n", a * b);
return 0;
}

// 6. Divide Two Numbers


#include <stdio.h>
int main() {
float a, b;
printf("Enter two numbers: ");
scanf("%f %f", &a, &b);
if (b != 0) {
printf("Quotient: %.2f\n", a / b);
} else {
printf("Division by zero is not allowed.\n");
}
return 0;
}

// 7. Print ASCII Value


#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf(" %c", &ch);
printf("ASCII value of %c: %d\n", ch, ch);
return 0;
}

// 8. Area of a Rectangle
#include <stdio.h>
int main() {
float length, width;
printf("Enter length and width: ");
scanf("%f %f", &length, &width);
printf("Area of rectangle: %.2f\n", length * width);
return 0;
}

// 9. Area of a Circle
#include <stdio.h>
#define PI 3.14159
int main() {

float radius;

printf("Enter radius: ");


scanf("%f", &radius);
printf("Area of circle: %.2f\n", PI * radius * radius);
return 0;
}

// 10. Perimeter of a Rectangle


#include <stdio.h>
int main() {
float length, width;
printf("Enter length and width: ");
scanf("%f %f", &length, &width);
printf("Perimeter of rectangle: %.2f\n", 2 * (length + width));
return 0;
}

// 11. Circumference of a Circle


#include <stdio.h>
#define PI 3.14159
int main() {
float radius;
printf("Enter radius: ");
scanf("%f", &radius);
printf("Circumference of circle: %.2f\n", 2 * PI * radius);
return 0;
}

// 12. Temperature Conversion (Celsius to Fahrenheit)


#include <stdio.h>
int main() {
float celsius;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
printf("Temperature in Fahrenheit: %.2f\n", (celsius * 9/5) + 32);
return 0;
}
// 13. Temperature Conversion (Fahrenheit to Celsius)
#include <stdio.h>
int main() {
float fahrenheit;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
printf("Temperature in Celsius: %.2f\n", (fahrenheit - 32) * 5/9);
return 0;
}

// 14. Sum of Three Numbers


#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
printf("Sum: %d\n", a + b + c);
return 0;
}

// 15. Simple Interest


#include <stdio.h>
int main() {
float principal, rate, time;
printf("Enter principal, rate, and time: ");
scanf("%f %f %f", &principal, &rate, &time);
printf("Simple Interest: %.2f\n", (principal * rate * time) / 100);
return 0;
}

// 16. Gross Salary Calculation


#include <stdio.h>
int main() {
float basic, hra, da;
printf("Enter basic salary, HRA, and DA: ");
scanf("%f %f %f", &basic, &hra, &da);
printf("Gross Salary: %.2f\n", basic + hra + da);
return 0;
}

// 17. Power Calculation


#include <stdio.h>
#include <math.h>
int main() {
double base, exponent;
printf("Enter base and exponent: ");
scanf("%lf %lf", &base, &exponent);
printf("Result: %.2lf\n", pow(base, exponent));
return 0;
}

// 18. Volume of a
Sphere #include <stdio.h>
#define PI 3.14159
int main()
{ float
radius;
printf("Enter radius: ");
scanf("%f", &radius);
printf("Volume of sphere: %.2f\n", (4.0/3) * PI * radius * radius * radius);
return 0;
}

// 19. Volume of a Cylinder


#include <stdio.h>
#define PI 3.14159
int main() {
float radius, height;
printf("Enter radius and height: ");
scanf("%f %f", &radius, &height);
printf("Volume of cylinder: %.2f\n", PI * radius * radius * height);
return 0;
}

// 20. Volume of a Cone


#include <stdio.h>
#define PI 3.14159
int main() {
float radius, height;
printf("Enter radius and height: ");
scanf("%f %f", &radius, &height);
printf("Volume of cone: %.2f\n", (1.0/3) * PI * radius * radius * height);
return 0;
}

// 21. Time Conversion


#include <stdio.h>
int main() {
int minutes;
printf("Enter minutes:
"); scanf("%d",
&minutes);
printf("%d hours and %d minutes\n", minutes / 60, minutes % 60);
return 0;
}

// 22. Speed Calculation


#include <stdio.h>
int main() {
float distance, time;
printf("Enter distance (km) and time (hours): ");
scanf("%f %f", &distance, &time);
printf("Speed: %.2f km/h\n", distance / time);
return 0;
}

// 23. Density Calculation


#include <stdio.h>
int main() {
float mass, volume;
printf("Enter mass and volume: ");
scanf("%f %f", &mass, &volume);
printf("Density: %.2f\n", mass / volume);
return 0;
}

// 24. Force Calculation


#include <stdio.h>
int main() {
float mass, acceleration;
printf("Enter mass and acceleration: ");
scanf("%f %f", &mass, &acceleration);
printf("Force: %.2f\n", mass * acceleration);
return 0;
}

// 25. Compound Interest


#include <stdio.h>
#include <math.h>
int main() {
float principal, rate, time;
printf("Enter principal, rate, and time: ");
scanf("%f %f %f", &principal, &rate, &time);
printf("Compound Interest: %.2f\n", principal * pow((1 + rate / 100), time) - principal);
return 0;
}

// 26. Percentage Calculation


#include <stdio.h>
int main() {
float marks_obtained, total_marks;
printf("Enter marks obtained and total marks: ");
scanf("%f %f", &marks_obtained, &total_marks);
printf("Percentage: %.2f%%\n", (marks_obtained / total_marks) * 100);
return 0;
}

// 27. Unit Conversion (km to miles)


#include <stdio.h>
int main() {
float km;
printf("Enter kilometers: ");
scanf("%f", &km);
printf("Miles: %.2f\n", km * 0.621371);
return 0;
}

// 28. Unit Conversion (kg to pounds)


#include <stdio.h>
int main() {
float kg;
printf("Enter kilograms: ");
scanf("%f", &kg);
printf("Pounds: %.2f\n", kg * 2.20462);
return 0;
}

// 29. Surface Area of a Football


#include <stdio.h>
#define PI 3.14159
int main() {
float radius;
printf("Enter radius of the football: ");
scanf("%f", &radius);
printf("Surface area of football: %.2f\n", 4 * PI * radius * radius);
return 0;
}

// 30. Swap 2 Numbers Using Third Variable


#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d, b = %d\n", a, b);
return 0;
}

You might also like