D Lab i (related tocos ×te writeln C. InThis Assi9X C D file/ handout.pdf Lab 1
ID: 3723941 • Letter: D
Question
D Lab i (related tocos ×te writeln C. InThis Assi9X C D file/ handout.pdf Lab 1 (related to COME 1213 Chapter 1) 2. Write a program that inputs two integers and divides the first one with the second one. Then it prints out the two numbers and the division result (float with 2 digits after the point). Be sure to use proper formatting and appropriate comments in your code. Provide appropriate prompts to the user. The output should be labeled clearly and formatted neatly. If the second number is zero, the division result should be "Can't divide by zero." Exl: if the inputs are 6 and 3, the output should be: 6 32.00 Ex2. if the inputs are 6 and 0, the output should be: 6 0 Can't divide by zero.Explanation / Answer
PLEASE REFER BELOW CODE
#include<stdlib.h>
#include<stdio.h>
int main()
{
int num,den;
float result;
//Asking user input for 1st and 2nd number
printf("Enter first number : ");
scanf("%d", &num);
printf("Enter Second number : ");
scanf("%d", &den);
//if 2nd number is 0 then we have to print the message
if(den == 0)
{
printf("Can't divide by zero ");
}
else
{
//dividing first one with second
result = num/den;
//printing the result
printf("%d %d %.2f", num,den,result);
}
return 0;
}
PLEASE REFER BELOW OUTPUT
Enter first number : 6
Enter Second number : 3
6 3 2.00
Process returned 0 (0x0) execution time : 3.515 s
Press any key to continue.
--------------------------------------------------------------------------------------------------------
Enter first number : 6
Enter Second number : 0
Can't divide by zero
Process returned 0 (0x0) execution time : 10.945 s
Press any key to continue.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.