Question #82888

a program that uses functions to return the product,sum and modulus of two positive numbers entered by a user.the program should have a dashboard that allows the user to select the computation he wishes to be done.
1

Expert's answer

2018-11-12T07:06:09-0500
#include <stdio.h>
int main(void)
{
// Defining variables for positive numbers and computation type to be done
unsigned int a, b, compType;
// Reading positive numbers
printf("Input two positive numbers separated by space:");
scanf("%u %u", &a, &b);
// Reading computation type
do{
printf("Input computation type\n");
printf("1 - product\n");
printf("2 - sum\n");
printf("3 - modulus\n");
scanf("%u", &compType);
} while (compType < 1 || compType > 3);
// Computing
switch (compType) {
case 1: { // product
printf("Product equals: %u\n", a*b);
break;
}
case 2: { // sum
printf("Sum equals: %u\n", a+b);
break;
}
case 3: {
if (!b) {
printf("Modulus cannot be computed since the divisor equals to zero.\n");
}
else {
printf("Modulus equals: %u\n", a % b);
}
break;
}
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS