In this post, we will learn how to divide two numbers using C Programming language.
This program will take two numbers as input from the user and divide those two numbers using / operator. For example: If the user enters 42 and 7, then this program will return 6 which is the quotient.
So, without further ado, let’s begin this tutorial.
C Program To Divide Two Numbers
//C Program To Divide Two Numbers #include<stdio.h> int main(){ int num1, num2, quotient; //Asking for input printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); //Computing quotient quotient = num1 / num2; printf("Quotient: %d", quotient); return 0; }
Output
Enter first number: 456
Enter second number: 7
Quotient: 65
How Does This Program Work ?
int num1, num2, quotient;
In this program, we have declared some int data type variables which will store the input numbers and the quotient.
//Asking for input printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2);
Then, the user is asked to enter the value of two numbers.
//Computing quotient quotient = num1 / num2;
After dividing the two numbers with the help of / operator, we get the quotient.
printf("Quotient: %d", quotient);
Finally, the result is displayed to the screen using printf() function.
Conclusion
I hope after going through this post, you understand how to divide two numbers using C Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.
Also Read: