You are on page 1of 1

C programming assignment solution

Assignment 2
Question one : write a C programe to compute the perimeter(circumference) and area of a circle with
a given radius?

Solution :
In c programming pi is written as M_pi (all letters are capital ).

#include <stdio.h>
#include <math.h> //qeybtaan iska tir haddaad mobile isticmalaysid
int main()
{
float radius;
printf("Enter radius: ");
scanf("%f", &radius);
float area = M_PI * radius * radius;
float circumference = 2 * M_PI * radius;
printf("The area of the circle is %f\n", area);
printf("The circumference of the circle is %f", circumference);
return 0;
}

Question 2 : Write a C programe to convert specified days into years, weeks and days?

Solution :

1 #include <stdio.h>
2 int main()
3{
4 int total_days = 200;
5 total_days = total_days % 365;
6 int years = total_days / 365;
7 int weeks = (total_days % 365) / 7;
8 int days = (total_days % 365) % 7;
9 printf("years : %d\nweeks : %d\ndays : %d\n", years, weeks, days);
10 return 0;
11 }
Question 3 : Write a C programe that accepts three intengers and find the maximum of the three?

You might also like