C Exercises: Read two numbers and divide the first number by second number
C Basic Declarations and Expressions: Exercise-38 with Solution
Write a program that reads two numbers and divides the first number by the second number. If division is not possible print "Division is not possible".
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int x, y;
float div_result;
// Prompt for user input
printf("Input two numbers: ");
printf("\nx: ");
scanf("%d", &x);
printf("y: ");
scanf("%d", &y);
// Check if division is possible
if(y != 0) {
div_result = x/y;
printf("%.1f\n", div_result);
} else {
printf("Division not possible.\n");
}
return 0;
}
Sample Output:
Input two numbers: x: 25 y: 5 5.0
Flowchart:

C programming Code Editor:
Previous: Write a C program to read the coordinate(x, y) (in Cartesian system) and find the quadrant to which it belongs (Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV).
Next: Write a C program to calculate the sum of all number not divisible by 17 between two given integer numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join