Académique Documents
Professionnel Documents
Culture Documents
LAB
ASSIGMENT 1
Question 1
QUESTION 2
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a = 5;
int b = 6;
int c = 7;
cout << "swapping";
cout << "x=";
cout << a;
cout << "y=";
cout << b;
c = a;
a = b;
b = c;
cout << "swapping";
cout << "x=";
cout << a;
cout << "y=";
cout << b;
}
QUESTION 3
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a, b,c;
cout << "enter first number";
cin >> a;
cout << "engter second number";
cin >> b;
c = a + b;
cout << c;
}
QUESTION 4
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int x, y, z;
cout << "enter three numbers";
cin >> x >> y >> z;
cout << x << "\n" << y << "\n" << z << "\n";
{
if (x > y&& x > z) {
cout << "it is the greater of the two";
cout << x;
}
else if (y > x&& y > z) {
cout << "it is the greater of the two";
cout << y;
}
else if (z > x&& z > y) {
cout << "it is the greater of the two";
cout << z;
}
else
cout << "all are equal";
}
{
if (x < y && x < z) {
cout << "it is the smallest of the three" << "\n";
cout << x;
}
else if (y < x && y < z) {
cout << "it is the samllest of the three" << "\n";
cout << y;
}
else if (z < x && z < y) {
cout << "it is the smallest of the three" << "\n";
cout << z;
}
else
cout << "all are equal";
}
}
QUESTION 4
“ASCENDING ORDER”
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int x, y, z;
cin >> x >> y >> z;
if (x < y && y < z)
cout << x << "<" << y << "<" << z;
else if (x < z && z < y)
cout << x << "<" << z << "<" << y;
else if (y < x && x < z)
cout << y << "<" << x << "<" << z;
else if (y < z && z < x)
cout << y << "<" << z << "<" << x;
else if (z < x && x < y)
cout << z << "<" << x << "<" << y;
else
cout << z << "<" << y << "<" << x;
}
ASSIGMENT 2
QUESTION 1
AREA OF RECTANLGE
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a, b, r;
cout << "enter number";
cin >> a;
cin >> b;
if (a > 0 && b > 0) {
r = a * b;
cout << "area of rectangle";
cout << r;
}
else
cout << "number is negative";
}
QUESTION 2
CALCULATOR
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
char op;
float f, s;
cout << "enter operator";
cin >> op;
cout << "Enter two operands=";
cin >> f >> s;
switch(op){
case '+':
cout << "addition"<< f + s;
break;
case '-':
cout << "subtraction"<< f - s;
break;
case '*':
cout << "multiplication"<< f * s;
break;
case '/':
cout << "division"<< f / s;
break;
default:
cout << "invalid operand";
}
}
QUESTION 3
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int cost, sale, r;
cout << "enter cost price";
cin >> cost;
cout << "enter sale price";
cin >> sale;
r = cost - sale;
r = sale - cost;
if (r > 0)
cout << "profit is=" << r;
else if (r < 0)
cout << "loss=" << r;
else
cout << "no profit no loss";
}
QUESTION 4
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int days, years,rem1,rem2, months, remdays;
cout << "Enter days ";
cin >> days;
years = days / 365;