Find division of two numbers
Table of Contents
In this tutorial, we will discuss the Perform division of two numbers in C language
In this post, we are going to learn how to perform division of two numbers using different 6 ways
Program 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,division;//variable declaration
num1=35,num2=5;//variable initialization
division=num1/num2;//calculate division
printf("Division of %d and %d is: %d",num1,num2,division);
//display result on the screen
getch();
return 0;
} When the above code is executed, it produces the following result
Division of 35 and 7 is:5
Approach
Program 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,division;//variable declaration
printf("Enter two numbers: ");//Ask the input from the user
scanf("%d %d",&num1,&num2);//Store the given input
division=num1/num2;//Calculate the division
printf("division of %d and %d : %d",num1,num2,division);
getch();
return 0;
} When the above code is executed, it produces the following result
Enter two numbers: 1000 40 division of 1000 and 40: 25
Approach
Program 3
#include <stdio.h>
#include <stdlib.h>
int division(int,int); //function prototype / declaration
int main()
{
int num1,num2,result;
printf("Enter two number\n");
scanf("%d %d",&num1,&num2); //numbers receive from the user
result=division(num1,num2);//assign the output to variable result
//function call
printf("division of %d and %d is %d\n",num1,num2,result);
getch();
return 0;
}
int division(int a, int b)//function definition
{
return a/b;
} When the above code is executed, it produces the following result
Enter two number 450 15 Division of 450 and 15 is: 30
Approach
Program 4
#include <stdio.h>
#include <stdlib.h>
int division(int,int); //function prototype / declaration
int main()
{
int num1,num2,result;
printf("Enter two number to find division\n");
scanf("%d %d",&num1,&num2); //numbers receive from the user
result=division(num1,num2);//assign the output to variable result
//function call
printf("Division of %d and %d is %d\n",num1,num2,result);
getch();
return 0;
}
int division(int x, int y)
{
if (y==0)
{
return 0;
}
else if (x-y==0){
return 1;
}
else if (x<y){
return 0;
}
else{
return (1+division(x-y,y));
}
}
When the above code is executed, it produces the following result
Enter two number to find division
2400
40
Division of 2400 and 40 is: 60
Approach
Program 5
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,*ptr1,*ptr2,division;
printf("Enter two number to find division\n");
scanf("%d %d",&num1,&num2); //numbers receive from the user
//function call
ptr1=&num1;
ptr2=&num2;
division=*ptr1 / *ptr2;
printf("division of %d and %d is %d\n",num1,num2,division);
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter two number to find division 12345 15 Division of 12345 and 15 is: 823
Approach
Program 6
#include <stdio.h>
#include <stdlib.h>
int division(int,int); //function prototype / declaration
int main()
{
int num1,num2,a,b,count=0;
printf("Enter two number to find division\n");
scanf("%d %d",&a,&b); //numbers receive from the user
num1=a;
num2=b;
while(num1>=num2)
{
num1=num1-num2;
count++;
}
//function call
printf("division of %d and %d is %d\n",a,b,count);
getch();
return 0;
} When the above code is executed, it produces the following result
Enter two number to find division
250
50
Division of 12345 and 15 is: 5
Suggested for you
Data type in C language
Variable in C language
Similar post
Perform division of two numbers in C++ language|using 6ways
Perform division of two numbers in Java language|using 5ways
Perform division of two numbers in Python language|using 4ways
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.