0% found this document useful (0 votes)
25 views2 pages

CSE-23078 - DSE - 163 - Assignment 4

This document contains C program code snippets to solve 3 programming problems: 1) Read the number of holidays in each month and find the month with minimum and maximum holidays. 2) Read temperature in Fahrenheit and display equivalent Celsius value using the conversion formula. 3) Read radius of a circle and calculate/display its area and circumference using the area and circumference formulas.

Uploaded by

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

CSE-23078 - DSE - 163 - Assignment 4

This document contains C program code snippets to solve 3 programming problems: 1) Read the number of holidays in each month and find the month with minimum and maximum holidays. 2) Read temperature in Fahrenheit and display equivalent Celsius value using the conversion formula. 3) Read radius of a circle and calculate/display its area and circumference using the area and circumference formulas.

Uploaded by

sandunmaheesha01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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