I have a homework question that is asking to write a c program for sum average p
ID: 3742587 • Letter: I
Question
I have a homework question that is asking to write a c program for sum average product and the smallest and largest of three integers, my completed program is below, however I was told by my instructer that because we havn't learned about the && operation or the if-else operation I am not allowed to use it. so I need to make a code for the smallest and largest of three integers without the use of &&/ if-else operations.
#include <stdio.h>
int main (void)
{
//declare variables
int num1, num2, num3;
//exectuable statments
/* prompt the user to inpute three integers */
printf("%s", "Enter three different integers using a space inbetween each: ");
scanf("%d %d %d", &num1, &num2, &num3);
//determin the sum of the three integers
printf("The sum is = %d ", num1 + num2 + num3);
//determin the average of the three integers
printf("The average is = %d ", (num1 + num2 + num3)/3);
//determin the product of the three integers
printf("the product is = %d ", num1 * num2 * num3);
//determin the smallest of the three integers
printf("the smallest is ");
if (num1 < num2 && num1 < num3)printf("%d ",num1);
if (num2 < num1 && num2 < num3)printf("%d ",num2);
if (num3 < num1 && num3 < num2)printf("%d ",num3);
//determin the smallest of the three integers
printf("the largest is ");
if (num1 > num2 && num1 > num3)printf("%d ",num1);
if (num2 > num1 && num2 > num3)printf("%d ",num2);
if (num3 > num1 && num3 > num2)printf("%d ",num3);
return 0;
}
// end function main
Explanation / Answer
#include <stdio.h>
int main (void)
{
//declare variables
int num1, num2, num3;
//exectuable statments
/* prompt the user to inpute three integers */
printf("%s", "Enter three different integers using a space inbetween each: ");
scanf("%d %d %d", &num1, &num2, &num3);
//determin the sum of the three integers
printf("The sum is = %d ", num1 + num2 + num3);
//determin the average of the three integers
printf("The average is = %d ", (num1 + num2 + num3)/3);
//determin the product of the three integers
printf("the product is = %d ", num1 * num2 * num3);
//determin the smallest of the three integers
// taking smallest into variable num1
num1 = (num1 < num2) ? num1:num2;
num1 = (num1 < num3) ? num1:num3;
printf("the smallest is %d ",num1);
// taking largest into variable num2
num2 = (num2 > num3) ? num2:num3;
printf("the largest is %d ",num2);
return 0;
}
// end function main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.