Problem 4 Write a C program, called calculator.c, that does the following. The p
ID: 3590700 • Letter: P
Question
Problem 4 Write a C program, called calculator.c, that does the following. The program should prompt the user to enter two positive integers x and y, read these integers, and then output the following values: x+y, x,y, x/y, x% y where x % y denotes the remainder obtained when x is divided by y. The prograrn should also explain for the user the values that it outputs. Notice that the ratio x/y should be computed using integer di- vision in C; thus this ratio is truncated if y does not divide x exactly. Finally, observe that in order to 3 print the character & to the screen, you should include 8t if the format string of the printf function. Here is a sample run of such a program, assuming that the executable file is called calculator home/userxYz/ECE15/Lab0> calculator Enter x: 20 Enter y: 6 Here are the results: x+y = 26 x*y = 120 x/y = 3 x%y = 2Explanation / Answer
// C Program
#include <stdio.h>
int main(void)
{
int x,y; //varible declaration part
//prompt for x value
printf("Enter x ");
scanf("%d",&x);
//prompt for y value
printf("Enter y ");
scanf("%d",&y);
printf("x+y = %d ",x+y); //display sum
printf("x*y = %d ",x*y); //display multiplicatio
printf("x/y = %d ",x/y); //display division
printf("x%%y = %d ",x%y); //display modulas
}
Output :
Enter x
10
Enter y
2
x+y = 12
x*y = 20
x/y = 5
x%y = 0
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.