Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

C Programming Solution

This document contains solutions to 7 coding questions/problems in C programming. The questions cover topics like calculating the area and circumference of a circle given the radius, converting days to years/weeks/days, finding the maximum of 3 integers, converting seconds to hours/minutes/seconds, performing arithmetic operations on 2 numbers, calculating the perimeter of a rectangle given length and breadth, and calculating sum, average, and percentage of 5 subjects. The solutions provided utilize basic C programming concepts like input/output, if-else statements, arithmetic operators, and formatting output.

Uploaded by

Liga
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)
24 views

C Programming Solution

This document contains solutions to 7 coding questions/problems in C programming. The questions cover topics like calculating the area and circumference of a circle given the radius, converting days to years/weeks/days, finding the maximum of 3 integers, converting seconds to hours/minutes/seconds, performing arithmetic operations on 2 numbers, calculating the perimeter of a rectangle given length and breadth, and calculating sum, average, and percentage of 5 subjects. The solutions provided utilize basic C programming concepts like input/output, if-else statements, arithmetic operators, and formatting output.

Uploaded by

Liga
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/ 3

C programming assignment solution

Assignment 2
Question 1 : 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 ).

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

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?

1 #include <stdio.h>
2 int main()
3{
4 float x, y, z;
5 printf("Enter three intengers : ");
6 scanf("%f %f %f", &x, &y, &z);
7 if (x > y && x > z)
8 {
9 printf("X (%f) is the maximum ", x);
10 }
11 if (y > x && y > z)
12 {
13 printf("y (%f) is the maximum ", y);
14 }
15 if (z > x && z > y)
16 {
17 printf("z (%f) is the maximum ", z);
18 }
19 return 0;
20 }

Question 4 : Write a C programe to convert a given integer (in seconds) to hours, minutes and
sendonds?

Solution :

#include <stdio.h>
1
int main()
2
{
3
int total_seconds = 1230;
4
total_seconds = total_seconds % 3600;
5
int hours = total_seconds / 3600;
6
int minutes = (total_seconds % 3600) / 60;
7
int seconds = (total_seconds % 3600) % 60;
8
printf("years : %d\nminutes : %d\n seconds : %d\n", hours, minutes,
9
seconds);
10
return 0;
11
}

Question 5 : Write a C programe to enter two numbers and perform all the arthimetic operations?

Solution :
#include <stdio.h>
1
int main()
2
{
3
float a, b;
4
printf("Enter a :");
5
scanf("%f", &a);
6
printf("Enter b: ");
7
scanf("%f", &b);
8
printf("Sum is %f\nDifference is %f\nProduct is %f\nQotient is %f\n",
9
a + b, a - b, a * b, a / b);
10
return 0;
11
}

Question 6 : Write a C programe to enter length and breadth of a rectangle and find its perimeter?

Solution :

1 #include <stdio.h>
2 int main()
3{
4 float length, breadth;
5 printf("Enter length: ");
6 scanf("%f", &length);
7 printf("Enter breadth: ");
8 scanf("%f", &breadth);
9 float perimter = 2 * (length + breadth);
10 printf("The perimeter is %f.", perimter);
11 return 0;
12 }
Question 7 :

#include <stdio.h>
1
int main()
2
{
3
float math, phy, eng, aplied, circuit;
4
math = 23;
5
phy = 27;
6
eng = 29;
7
aplied = 22;
8
circuit = 25;
9
float sum = math + phy + circuit + eng + aplied;
10
float average = sum / 5;
11
float persentage = (average / 30) * 100;
12
printf("Sum is %f\nAverage is %f\npercentage is %f\n", sum, average,
13
persentage);
14
15
return 0;
16
} Coded and written by Eng Liban

You might also like