0% found this document useful (0 votes)
5 views

Code

This document contains 5 C programs that perform various calculations and conversions. The first program calculates the sum, difference, product, and quotient of two input numbers as well as the remainder. The second program calculates the area and perimeter of a rectangle given its length and width. The third program converts feet and inches to centimeters. The fourth program converts Fahrenheit to Celsius. The fifth program converts seconds to hours, minutes and seconds.

Uploaded by

Ryuu Akagi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Code

This document contains 5 C programs that perform various calculations and conversions. The first program calculates the sum, difference, product, and quotient of two input numbers as well as the remainder. The second program calculates the area and perimeter of a rectangle given its length and width. The third program converts feet and inches to centimeters. The fourth program converts Fahrenheit to Celsius. The fifth program converts seconds to hours, minutes and seconds.

Uploaded by

Ryuu Akagi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. #include <stdio.

h>

int main(){
int num1, num2;

printf("Enter first number: ");


scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);

printf("Sum=%d\n", num1 + num2);


printf("Difference=%d\n", num1 - num2);
printf("Product=%d\n", num1 * num2);
printf("Quotient=%d\n", num1 / num2);
printf("Remainder=%d\n", num1 % num2);

return 0;
}

2. #include <stdio.h>

int main() {
double length, width, area, perimeter;

printf("Enter the length: ");


scanf("%lf", &length);
printf("Enter the width: ");
scanf("%lf", &width);

area = length * width;


perimeter = 2 * (length + width);

printf("Area=%.6lf\n", area);
printf("Perimeter=%.6lf\n", perimeter);

return 0;
}

3. #include <stdio.h>

int main() {
float feet, inches;

printf("Enter distance<feet>: ");


scanf("%f", &feet);

float feet_cm = feet * 30.48;


printf("%.6lf feet = %.6lf cm\n", feet, feet_cm);

printf("Enter distance<inches>: ");


scanf("%f", &inches);

float inches_cm = inches * 2.54;


printf("%.6lf inches = %.6lf cm\n", inches, inches_cm);

return 0;
}

4. #include <stdio.h>

int main() {
float farenheit, celsius;

printf("Enter the temperature in Farenheit:");


scanf("%f", &farenheit);

celsius = (5.0 / 9.0) * (farenheit - 32);

printf("Farenheit temperature is: %.6f\n", farenheit);


printf("Celsius temperature is: %.6f\n", celsius);

return 0;
}

5. #include <stdio.h>

int main() {
int seconds, hours, minutes;

printf("Enter time <seconds>: ");


scanf("%d", &seconds);

hours = seconds/3600;
minutes = (seconds % 3600)/60;
seconds %= 60;

printf("Time is %d hours, %d minutes, and %d seconds\n", hours, minutes, seconds);

return 0;
}

You might also like