For this assignment, you will write a C program called uno.c which reads in two
ID: 3631182 • Letter: F
Question
For this assignment, you will write a C program called uno.c which reads in two integers from the user, and tells them a little bit about the two numbers. See the example output for the exact output expected from your program.Part A Read in the numbers and tell them the numbers they entered. Part B Display the result of dividing the first number by the second, using floating-point division. What if the second number is zero? Check the examples. Part C Display the absolute value of the difference of the numbers.
You need to include the stdlib.h header file to make use of the abs function, or you can use if statements. Part D Display which number is bigger. Part E Display which numbers are divisible by three. This one is tricky. Look carefully at the examples, below. What should you print if one is divisible and one isn’t? What if both are divisible? Read the examples, below. For the record: 11 is not divisible by three, but 0 is, and so is -12.
Requirements
?You must turn in the .c file; not the binary, not the executable, not the a.out.
?Your program must be named: uno.c
?Your output should be EXACTLY the same as below, given the input as specified.
?We will only test your code with integer input.
?You may assume that the user will type exactly one integer, when prompted.
?You must comment your code appropriately, including your name, date and purpose of the program at the very very very beginning of the file.
?You may ONLY use two int variables in your entire program. No other variables, of any type, are allowed.
Explanation / Answer
#include #include #include int main() { int s1,s2; printf("Please enter first integer : "); scanf("%i",&s1); printf("Please enter second integer : "); scanf("%i",&s2); printf(" You entered %i and %i " ,s1,s2); // Part a if(s2 != 0) { printf(" %i / %i = %.2f ",s1,s2,(float)s1 / s2); } else printf(" Error! Divide by 0 "); // Part b printf(" Absolute value of %i - %i = %i ",s1,s2,abs(s1-s2)); // Part c if(s1 > s2) printf(" first number %i : is the bigger ",s1); else printf(" second number %i : is the bigger ",s2); // Part d if( s1 % 3 == 0 && s2 % 3 == 0) // Part e printf(" Divisible by 3 : Both "); if( s1 % 3 != 0 && s2 % 3 != 0) printf(" Divisible by 3 : Neither "); if( s1 % 3 == 0 && s2 % 3 != 0) printf(" Divisible by 3 : only first(%i) ",s1); if( s1 % 3 != 0 && s2 % 3 == 0) printf(" Divisible by 3 : only second(%i) ",s2); getch(); return 0; } Please RateRelated 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.