Professional Documents
Culture Documents
ECE 431
ASSIGNMENT 3
PREPARED BY:
2009735957
EE2103A
PREPARED FOR:
Assignment 3
1) Using function(s), write C program to evaluate and print the area of the surfaces and volume
of a cube.
Solution:
#include <stdio.h>
float area(float x);
float vol(float x);
int main()
{
float length;
printf("Enter the size of the cube: ");
scanf("%f", &length);
printf("One surface area of the cube is %.2f unit square\n",area(length));
printf("A cube has 6 surface area\n");
printf("Total surface area of the cube is %.2f unit cube\n",area(length)*6.00);
printf("The volume of the cube is %.2f unit cube\n",vol(length));
return 0;
}
float area(float x)
{
float a;
a = x * x;
return a;
}
float vol(float x)
{
float v;
v = x * x * x;
return v;
}
ASSIGNMENT 3 ECE431
ASSIGNMENT 3 ECE431
2) A class of 30 students is taking 8 subjects for the coming examinations. Write a program that can
accept all the marks involved. Determine and print the average mark for each student. Hint: Use array
construct.
Solution:
#include <stdio.h>
int main()
{
int subject[8];
float average;
int i,s,total=0;
for(s=1;s<31;s++)
{
printf("Enter mark for student: %d\n",s);
for(i=1;i<9;i++)
{
printf("Enter mark for subject %d: ",i);
scanf("%d", &subject[i]);
total += subject[i];
}
printf("Total mark is: %d\n", total);
average = total/8.00;
printf("The average mark is: %.2f\n",average);
printf("\n");
average=0;
total=0;
}
return 0;
}
ASSIGNMENT 3 ECE431