Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Differentiate the modulo and division by using 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 −
#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
Advertisements