Differentiate Modulo and Division in C Programming Language



Modulo − Represents as % operator.

 And gives the value of the remainder of an integer division.

Division − represents as / operator.

 And gives the value of the quotient of a division.

Program 1

#include<stdio.h>
int main(){
   int a,b,c;
   printf("enter a,b,c values:");
   scanf("%d%d%d,&a,&b,&c);
   printf("a/b=%d a%b=%d
",a/b,a%b);    printf("(a+10)%b=%d (a+10)/b=%d
",(a+10)%b,(a+10)/b); }

Output

enter a,b,c values:2 4 6
a/b=0 ab=2
(a+10)b=0 (a+10)/b=3

Program 2

Applying pointer variables to perform modulo and division operation −

 Live Demo

#include<stdio.h>
void main(){
   //Declaring pointers and variables//
   int num1,num2;
   int *p1,*p2;
   p1=&num1;
   p2=&num2;
   int div,mod;
   //Reading User I/p//
   printf("Enter the values of num1 & num2: ");
   scanf("%d,%d",&num1,&num2);
   div=*p1/ *p2;
   mod=*p1%*p2;
   //Printing O/p//
   printf("Division value = %d
",div);    printf("Modulus value = %d
",mod); }

Output

Enter the values of num1 & num2: 30,20
Division value = 1
Modulus value = 10
Updated on: 2021-03-05T10:04:59+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements