You are on page 1of 2

DSE - 163 Computer Programming Concepts

Assignment 4
1.
a. Write a C program to read the number of holidays in each month in Sri
Lanka and find the month which has the minimum number of holidays
and the month which has the maximum number of holidays.

#include <stdio.h>

int main() {
int holidays[12];
char *months[12] = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};

for (int i = 0; i < 12; i++) {


printf("Enter the number of holidays in %s: ", months[i]);
scanf("%d", &holidays[i]);
}

int minHolidays = holidays[0]; // Initialize with the first month's holidays


int maxHolidays = holidays[0]; // Initialize with the first month's holidays
int minIndex = 0;
int maxIndex = 0;

for (int i = 1; i < 12; i++) {


if (holidays[i] < minHolidays) {
minHolidays = holidays[i];
minIndex = i;
}
if (holidays[i] > maxHolidays) {
maxHolidays = holidays[i];
maxIndex = i;
}
}
printf("Month with the minimum holidays: %s\n", months[minIndex]);
printf("Month with the maximum holidays: %s\n", months[maxIndex]);
return 0;
}
b. Write a C program to read the Temperature in Fahrenheit and display the
equivalent Celsius value. The equation to convert from Fahrenheit to Celsius
is given below:
C = (F-32)* (5/9) where C - Celsius value and F = Fahrenheit
Value

#include <stdio.h>

int main() {
float fahrenheit, celsius;

printf("Enter temperature in Fahrenheit: ");


scanf("%f", &fahrenheit);

celsius = (fahrenheit - 32) * 5 / 9;

printf("Equivalent Celsius value: %.2f\n", celsius);

return 0;
}

2. Write a C program to read the radius of a circle and display the area and the
circumference of that circle.
A = (22/7)* r * r where A = Area of the circle; r = radius of the
circle. C = 2*(22/7)*r where C = Circumference of the circle; r = radius of the
circle.

#include <stdio.h>

int main() {
float radius, area, circumference;
const float pi = 3.14159;

printf("Enter the radius of the circle: ");


scanf("%f", &radius);

area = pi * radius * radius;

circumference = 2 * pi * radius;

printf("Area of the circle: %.2f\n", area);


printf("Circumference of the circle: %.2f\n", circumference);

return 0;
}

You might also like