You are on page 1of 6

WEEK 2

Practical 1

INPUT

#include <iostream>
using namespace std;

int main (void)


{
cout << "Hello!\nHow are you?\n";

return 0;
}

OUTPUT
PART B
QUESTION 1
INPUT
#include <iostream>
using namespace std;

int main (void)


{
int number1, number2, number3, sum;

cout << "Enter first number: ";


cin >> number1;
cout << endl;

cout << "Enter second number: ";


cin >> number2;
cout << endl;

cout << "Enter third number: ";


cin >> number3;
cout << endl;

sum = number1 + number2 + number3;


cout << "The sum of "<<endl;
cout<< number1<<" ,"<< number2<< " and"<< number3<< "is " << sum << endl;

return 0;
}

OUTPUT
PART D
QUESTION 1
INPUT
#include <iostream>
using namespace std;

int main (void)


{
int number, square;

cout << "Enter a number: ";


cin >> number;
cout << endl;

square = number *number;


cout << "The square of ";
cout<< number<<"is " << square<< endl;

return 0;
}

OUTPUT
PART D
QUESTION 2
INPUT
#include <iostream>
using namespace std;

int main (void)


{
int a, b, product;

cout << "Enter two number (separated by space): ";


cin >> a>>b;
cout << endl;

product = a*b;
cout << "The product of ";
cout << a<<"and"<<b << "is " << product << endl;

return 0;
}

OUTPUT

OR
INPUT
#include <iostream>
using namespace std;

int main (void)


{
int a, b, product;

cout << "Enter first number: ";


cin >> a;
cout << endl;

cout << "Enter second number: ";


cin >> b;
cout << endl;

product =a*b;
cout << "The product of ";
cout << a<<"and"<<b << "is " << product << endl;

return 0;
}

OUTPUT
PART D
QUESTION 3
INPUT
#include <iostream>
using namespace std;

int main (void)


{
int width, length, area, perimeter;

cout << "Enter width: ";


cin >> width;
cout << endl;

cout << "Enter length: ";


cin >> length;
cout << endl;

area = width*length;
cout << "The area is" << area << endl;

perimeter = 2 * (width + length);


cout << "The perimeter is" << perimeter << endl;
return 0;
}

OUTPUT

You might also like