Program to find modulus of two numbers

Description

To find modulus of values in variables firstNumber and secondNumber, the
arithmetic operator % is used and the result is stored in the variable mod.

C/C++

/* C Program to find modulus of two numbers */
//Save it as ModulusTwoNumbers.c

#include<stdio.h>
int main(){

    int firstNumber, secondNumber, mod;

    printf("Enter first number : ");
    scanf("%d",&firstNumber);

    printf("Enter second number : ");
    scanf("%d",&secondNumber);

    mod = firstNumber % secondNumber;

    printf("The modulus of %d and %d is %d",firstNumber,secondNumber,mod);

    return 0;
}
Input:
Enter first number : 
15
Enter second number : 
2

Output:
The modulus of 15 and 2 is 1

Java

/* java Program to find modulus of two numbers */
//Save it as ModulusTwoNumbers.java

import java.io.*;
import java.util.Scanner;

public class ModulusTwoNumbers {

    public static void main(String[] args) {
        
            Scanner scanner = new Scanner(System.in);

            int firstNumber, secondNumber, mod;

        System.out.println("Enter first number : ");
        firstNumber = scanner.nextInt();

        System.out.println("Enter second number : ");
        secondNumber = scanner.nextInt();

        mod = firstNumber % secondNumber;

        System.out.println("The modulus of "+firstNumber+" and "+secondNumber+" is "+mod);
    }
}
Input:
Enter first number : 
15
Enter second number : 
2

Output:
The modulus of 15 and 2 is 1

Related Programs

1) Program to calculate power of a number
2) Program to calculate Permutation And Combination
3) Program to calculate Gross Salary
4) Program to calculate percentage mark of student
5) Program to calculate Grade of Student
6) Program to find the average of numbers in a given range
7) Program to generate Random number in a given Range
8) Program to Swap Two Numbers
9) Program to find sum of digits of a number
10) Program to reverse a number
11) Program to display multiplication table of a number
12) Program to Display Fibonacci Series
13) Program to print all Squares of numbers from 1 to given Range
14) Program to find sum of first and last digit of a number
15) Program to find factors of a Number
16) Program to add two complex numbers
17) Program to find Quotient and Remainder
Share Me

Leave a Reply