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

C Assignment 2

Uploaded by

qeyscade019
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)
3 views

C Assignment 2

Uploaded by

qeyscade019
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 :

1 #include <stdio.h>
2 #include <math.h>
3 int main()
4{
5 float radius;
6 printf("Enter radius: ");
7 scanf("%f", &radius);
8 float area = 3.142 * radius * radius;
9 float circumference = 2 * 3.142 * 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
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 program to enter two numbers and perform all the arithmetic operations?

Solution :

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

Question 6 : Write a C program 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("TheW perimeter is %f.", perimter);
11 return 0;
12 }
Question 7 : Write a C program to enter marks of five subjects and calculate total, average and
percentage?

Solution

#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