Question #18905

write a program in c which computes and prints product, difference, maximum, minimum, average, sum and modular

Expert's answer

int arrayofnumbers[20];

double Product();

double Difference();

double Maximum();

double Minimum();

double Average();

double Sum();

double Modular();

int main()

{

for(int i=0;i<20;i++){

printf("Enter number %d: ",(i+1));

scanf("%d",&arrayofnumbers[i]);

}

printf("

Product = %f",Product());

printf("

Difference = %f",Difference());

printf("

Maximum = %f",Maximum());

printf("

Minimum = %f",Minimum());

printf("

Average = %f",Average());

printf("

Sum = %f",Sum());

printf("

Modular = %f",Modular());

printf("

Press any key to exit...");

scanf("%d",&arrayofnumbers[0]);

return 0;

}

double Product(){

double product=1;

for(int i=0;i<20;i++){

product*=arrayofnumbers[i];

}

return product;

}

double Difference(){

double difference=arrayofnumbers[0];

for(int i=1;i<20;i++){

difference-=arrayofnumbers[i];

}

return difference;

}

double Maximum(){

double maximum=arrayofnumbers[0];

for(int i=0;i<20;i++){

if(arrayofnumbers[i]>maximum){

maximum =arrayofnumbers[i];

}

}

return maximum;

}

double Minimum(){

double minimum=arrayofnumbers[0];

for(int i=0;i<20;i++){

if(arrayofnumbers[i]<minimum){

minimum =arrayofnumbers[i];

}

}

return minimum;

}

double Average(){

double sum=0;

for(int i=0;i<20;i++){

sum+=arrayofnumbers[i];

}

return sum/20;

}

double Sum(){

double sum=0;

for(int i=0;i<20;i++){

sum+=arrayofnumbers[i];

}

return sum;

}

double Modular(){

double modular=0;

for(int i=0;i<20;i++){

modular =arrayofnumbers[i]%2;

}

return modular;

}

double Product();

double Difference();

double Maximum();

double Minimum();

double Average();

double Sum();

double Modular();

int main()

{

for(int i=0;i<20;i++){

printf("Enter number %d: ",(i+1));

scanf("%d",&arrayofnumbers[i]);

}

printf("

Product = %f",Product());

printf("

Difference = %f",Difference());

printf("

Maximum = %f",Maximum());

printf("

Minimum = %f",Minimum());

printf("

Average = %f",Average());

printf("

Sum = %f",Sum());

printf("

Modular = %f",Modular());

printf("

Press any key to exit...");

scanf("%d",&arrayofnumbers[0]);

return 0;

}

double Product(){

double product=1;

for(int i=0;i<20;i++){

product*=arrayofnumbers[i];

}

return product;

}

double Difference(){

double difference=arrayofnumbers[0];

for(int i=1;i<20;i++){

difference-=arrayofnumbers[i];

}

return difference;

}

double Maximum(){

double maximum=arrayofnumbers[0];

for(int i=0;i<20;i++){

if(arrayofnumbers[i]>maximum){

maximum =arrayofnumbers[i];

}

}

return maximum;

}

double Minimum(){

double minimum=arrayofnumbers[0];

for(int i=0;i<20;i++){

if(arrayofnumbers[i]<minimum){

minimum =arrayofnumbers[i];

}

}

return minimum;

}

double Average(){

double sum=0;

for(int i=0;i<20;i++){

sum+=arrayofnumbers[i];

}

return sum/20;

}

double Sum(){

double sum=0;

for(int i=0;i<20;i++){

sum+=arrayofnumbers[i];

}

return sum;

}

double Modular(){

double modular=0;

for(int i=0;i<20;i++){

modular =arrayofnumbers[i]%2;

}

return modular;

}

## Comments

## Leave a comment