01.Find the total and average of a sequence of 10 numbers stored in array.
Answer
#include <stdio.h>
int main()
{
float Total,Average;
int i;
float marks[10]={70,90,88,56,98,95,93,94,92,83};
Total=0;
Average=0;
for (i=0;i<10;i++)
{
Total=Total+marks[i];
}
printf("Total=%.2f\n",Total);
Average=Total/10;
printf("Average=%.2f",Average);
return 0;
}
2. Following list represents the data units used by three persons.
Create an array to store these details and print the list.
person work mobile home
1 500 1000 300
2 10 1800 200
3 200 400 700
Find the following using the above table;
I. Find the total unit consumed.
II. Find the total consumption of units for each phone type.
III. Who consumed maximum unites for mobile phones?
IV. Who pays highest phone bill?
V. Who pays lower phone bill?
VI. How many units are consumed by person 3?
Answer
#include <stdio.h>
int main()
{
int x,y,p1,p2,p3,Total_unit,W_total,M_total,H_total,max,min;
int table[3][4]={{1,500,1000,300},
{2,10,1800,200},
{3,200,400,700}};
printf("Person\t\t Work\t\t Mobile \t Home");
printf("\n");
for (x=0;x<3;x++){
for(y=0;y<4;y++)
printf("%4i\t\t",table[x][y]);
printf("\n");
}
Total_unit=0;
for (x=0;x<3;x++){
for(y=1;y<4;y++)
Total_unit=Total_unit+table[x][y];
printf("\n");
}
printf("Toatl unit consumed=%i\n\n",Total_unit);
W_total=table[0][1]+table[1][1]+table[2][1];
M_total=table[0][2]+table[1][2]+table[2][2];
H_total=table[0][3]+table[1][3]+table[2][3];
printf("Work total-->%i\n",W_total);
printf("Mobile total-->%i\n",M_total);
printf("Home total-->%i\n\n",H_total);
p1=table[0][1]+table[0][2]+table[0][3];
p2=table[1][1]+table[1][2]+table[1][3];
p3=table[2][1]+table[2][2]+table[2][3];
if (table[0][2]>table[1][2])
if (table[0][2]>table[2][2])
printf("Person 1 is consumed maximmum units for mobile phone");
else
printf("Person 3 is consumed maximmum units for mobile phone");
else
printf("Person 2 is consumed maximmum units for mobile phone");
printf("\n");
if(p1>p2)
if(p1>p3)
printf("Person 1 pays highest phone bill ");
else
printf("Person 3 pays highest phone bill ");
else
printf("Person 2 pays highest phone bill ");
printf("\n");
if(p1<p2)
if(p1<p3)
printf("Person 1 pays lowest phone bill\n ");
else
printf("Person 3 pays lowest phone bill\n ");
else
printf("Person 2 pays lowest phone bill\n ");
printf("Person 3 total-------->%i\n\n",p3);
return 0;
}
3. Find the minimum and maximum of sequence of 10 numbers stored in array.
Answer
#include <stdio.h>
int main() {
int numbers[10];
int i;
int min, max;
printf("Enter 10 numbers:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &numbers[i]);
}
min = max = numbers[0];
for (i = 1; i < 10; i++) {
if (numbers[i] < min) {
min = numbers[i];
}
if (numbers[i] > max) {
max = numbers[i];
}
}
printf("Minimum: %d\n", min);
printf("Maximum: %d\n", max);
return 0;
}
0 Comments