Sunday 15 September 2019

C++ Divide Two Numbers code

Method#1#include<iostream>
using namespace std;
void main()
{
int a=5. b=4,d; //Initializing variables
d=a/b; //Dividing the numbers and storing result in variable 'd'
cout<<"Result: "<<d<<endl; //Displaying the Result
return 0;
}



Method#2
#include<iostream>
using namespace std;

void main()
{

int a, b,d;  //Initializing variables
cout<<"Enter 1st Number: "<<endl; //Prompt a message to user
cin>>a; //Taking input the in variable 'a'
cout<<"Enter 2nd Number: "<<endl; //Prompt a message to user
cin>>b; //Taking input the in variable 'b'
d=a/b;  //Multiplying numbers and storing result in variable 'd'
cout<<"Result: "<<d<<endl;  //Displaying the Result
return 0;

}

No comments:

Post a Comment