This is C programming Your First C Program For this assignment, you will write a
ID: 3585464 • Letter: T
Question
This is C programming
Your First C Program For this assignment, you will write a C program called ints.c. This program reads two numbers from the user, and produces a few arguably-interesting facts about the numbers. See the example output for the exact output expected from your program. Here's an outline for the program: o Read in the two numbers o Display the result of dividing the first number by the second one, using floating-point division. What if the second number is zero? Check the examples. o Display the positive difference of the two numbers. o If either number is forty-two, say so. ° Display which numbers are evenly divisible by six. 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? For the record neither 13 nor 3 are divisible by 6, but 18, 0, and-90 are. Examples Here are a few example runs of the program. The % is the command prompt, text like this s typed by the user and the rest is from he program. You don't have to make it colored or underlined that's ust how it looks here, so you can tell who does what.) Don't be creative about your output it must look exactly like this (except for the leading spaces): % ·/a.out Two numbers, please: 123456 7 Dividing 123456/7: 17636.571429 Pos diff: 123449 Divisible: only 123456 % :/3, out Two numbers, please: 12 Dividing 1/2: . 500000 Pos diff: 1 Divisible: neither % i /a. out Two numbers, please: 5-18 Dividing 5/-18: 0.277778 Pos diff: 23 Divisible: only-18 % La.out Two numbers, please: 0 42 Dividing 0/42: 0.000000 Pos diff: 42 It's the answer! Divisible: both % La.out Two numbers, please: 0 e Dividing 0/0: against the rules Pos diff: Divisible: both % ·/a.out Two numbers, please: 5 0 Dividing 5/0: against the rules Pos diff: 5 Divisible : only % ·/a.out Two numbers, please: -33 Dividing 3/31.000000 Pos diff: 6 Divisible: neitherExplanation / Answer
#include<stdio.h>
int main(){
int a,b;
//get two numbers
printf("Two numbers, please:");
scanf("%d %d",&a,&b);
printf("Dividing %d/%d: ",a,b);
// check if denominator is zero
if(b==0){
printf("against the rules. ");
}
else{
//get float division value
float f = (float)a/b;
printf("%f ",f);
}
//get absolute difference
int c = a - b;
if(c<0){
c = -c;
}
printf("Pos diff: %d ",c);
// check if a number is 42
if(a==42 || b==42){
printf("It's the answer! ");
}
//check divisibility by 6
if(a%6==0 && b%6==0){
printf("Divisible: both ");
}
else if(a%6==0){
printf("Divisible: only %d ",a);
}
else if(b%6==0){
printf("Divisible: only %d ",b);
}
else{
printf("Divisible: neither ");
}
return 0;
}
/*
sample output
Two numbers, please: 123456 7
Dividing 123456/7: 17636.572266
Pos diff: 123449
Divisible: only 123456
Two numbers, please: 1 2
Dividing 1/2: 0.500000
Pos diff: 1
Divisible: neither
Two numbers, please: 5 -18
Dividing 5/-18: -0.277778
Pos diff: 23
Divisible: only -18
Two numbers, please: 0 42
Dividing 0/42: 0.000000
Pos diff: 42
It's the answer!
Divisible: both
Two numbers, please: 0 0
Dividing 0/0: against the rules.
Pos diff: 0
Divisible: both
Two numbers, please: -3 3
Dividing -3/3: -1.000000
Pos diff: 6
Divisible: neither
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.