C++ program to perform Modulus on one integer and one float ( logic explained )

Here is the C++ program to perform Modulus on one integer and one float.  You all should have in mind how it works exactly. Here is the algorithm.
Steps
User side:
1: User asked to enter a float value .
2: User asked to enter an integer value .
3: User displayed the result.
Developer side
1: Declare variables that are going to be used in program.
2: Input a float value from user.
3: Input an integer value from user.
4: We cannot take modulus of a float value ,So we must change it to integer. To do so store this float value to an integer type variable.
5: Now take modulus of that integer type variable with the one entered by user.
6: Program end.

Code:

#include<iostream>


using namespace std;

int main()
{
      
       float f,f2;
       int i1,i2;
       cout<<"Enter First Float : ";
       cin>>f;
       cout<<"Enter Second Integer : ";
       cin>>f2;
       i1=f;
       i2=f2;
       cout<<"Modulus : "<<i1%i2;
      
       cout << "\n\n";
       system("pause");
       return 0;

}

Output

Comments

  1. Replies
    1. Wait I will be uploading code for 2d games and some learning management systems its just start. This one for first semester students .

      Delete

Post a Comment