Assignment no 1 NAME: SHAFIQUE YOUNAS ROLL NO: 1655 CLASS: BS TECH ELECTRICAL (MORNING) SEMESTER : 2ND
SUPERIOR UNIVERSITY LAHORE
C++ Program to Perform Addition Subtraction Multiplication Division and Modular #include "stdafx.h" #include #include using namespace std; Void main() { int a, b, res; cout << "Enter First number :"; cin >> a; cout << "Enter Second number :"; cin >> b; res = a + b; cout << "\nAddition = " << res; res = a - b; cout << "\nSubtraction = " << res; res = a*b; cout << "\nMultiplication = " << res; res = a / b; cout << "\nDivision = " << res; res = a % b; cout << "\nModular = " << res; getch(); }
Output: Enter First number: 4
Enter Second number: 3 Addition = 7 Subtraction = 1 Multiplication = 12 Division = 1 Modular = 1
#include "stdafx.h" # include #include using namespace std; void main() { int a, b; char ch; cout << "Enter first Number :"; cin >> a; cout << "Enter second Number :"; cin >> b; cout << "Enter operator (+, -, *, /, %) :"; cin >> ch; if (ch == '+') cout << "Result = " << a + b; else if (ch == '-') cout << "Result = " << a - b; else if (ch == '*') cout << "Result = " << a*b; else if (ch == '/') cout << "Result = " << a / b; else if (ch == '%') cout << "Result = " << a % b; else cout << "Wrong Operator!!!"; getch(); }
Output: Enter first Number: 5 Enter second Number: 3 Enter operator (+, -, *, /, %): + Result = 8
C++ Program to Perform Addition Subtraction Multiplication Division and Modular #include "stdafx.h" #include #include using namespace std; Void main() { int a, b, res; cout << "Enter First number :"; cin >> a; cout << "Enter Second number :"; cin >> b; res = a + b; cout << "\nAddition = " << res; res = a - b; cout << "\nSubtraction = " << res; res = a*b; cout << "\nMultiplication = " << res; res = a / b; cout << "\nDivision = " << res;
res = a % b; cout << "\nModular = " << res; getch(); }
Output: Enter First number: 4 Enter Second number: 3 Addition = 7 Subtraction = 1 Multiplication = 12 Division = 1 Modular = 1
#include "stdafx.h" # include #include using namespace std; void main() { int a, b; char ch; cout << "Enter first Number :"; cin >> a; cout << "Enter second Number :"; cin >> b; cout << "Enter operator (+, -, *, /, %) :"; cin >> ch; if (ch == '+') cout << "Result = " << a + b; else if (ch == '-') cout << "Result = " << a - b; else if (ch == '*') cout << "Result = " << a*b;
else if (ch == '/') cout << "Result = " << a / b; else if (ch == '%') cout << "Result = " << a % b; else cout << "Wrong Operator!!!"; getch(); }
Output: Enter first Number: 5 Enter second Number: 3 Enter operator (+, -, *, /, %): + Result = 8