Differentiate the modulo and division by using C Programming language?

CServer Side ProgrammingProgramming

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\n",a/b,a%b);
   printf("(a+10)%b=%d (a+10)/b=%d\n",(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\n",div);
   printf("Modulus value = %d\n",mod);
}

Output

Enter the values of num1 & num2: 30,20
Division value = 1
Modulus value = 10
raja
Published on 05-Mar-2021 10:03:54
Advertisements