1.
/**
* C program to find perimeter of rectangle
*/
#include <stdio.h>
int main()
{
float length,breadth, perimeter;
/*
* Input length and breadth of rectangle from user
*/
printf("Enter length of the rectangle: ");
scanf("%f", &length);
printf("Enter breadth of the rectangle: ");
scanf("%f", &breadth);
/* Calculate perimeter of rectangle */
perimeter = 2 * (length + breadth);
/* Print perimeter of rectangle */
printf("Perimeter of rectangle = %f units ", perimeter);
return 0;
}
2.
/**
* C program to calculate total, average and percentage of five subjects
*/
#include <stdio.h>
int main()
{
float bio, phy, geo, math, comp;
float total, average, percentage;
/* Input marks of all five subjects */
printf("Enter marks of five subjects: \n");
scanf("%f%f%f%f%f", &bio, &phy, &geo, &math, &comp);
/* Calculate total, average and percentage */
total = bio + phy + geo + math + comp;
average = total / 5.0;
percentage = (total / 500.0) * 100;
/* Print all results */
printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);
return 0;
}
3.
/**
* C program to find the greatest in three numbers
*/
#include <stdio.h>
int main() {
double n1, n2, n3;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
// outer if statement
if (n1 >= n2) {
// inner if...else
if (n1 >= n3)
printf("%.2lf is the largest number.", n1);
else
printf("%.2lf is the largest number.", n3);
}
// outer else statement
else {
// inner if...else
if (n2 >= n3)
printf("%.2lf is the largest number.", n2);
else
printf("%.2lf is the largest number.", n3);
}
return 0;
}
4.
/**
* C program to calculate simple interest
*/
#include <stdio.h>
int main()
{
float principle, time, rate, SI;
/* Input principle, rate and time */
printf("Enter principle (amount): ");
scanf("%f", &principle);
printf("Enter time: ");
scanf("%f", &time);
printf("Enter rate: ");
scanf("%f", &rate);
/* Calculate simple interest */
SI = (principle * time * rate) / 100;
/* Print the resultant value of SI */
printf("Simple Interest = %f", SI);
return 0;
}
5.
/**
* C program to convert temperature from degree celsius to fahrenheit
*/
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
/* Input temperature in celsius */
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
/* celsius to fahrenheit conversion formula */
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}