0% found this document useful (0 votes)
23 views

Week 2 Practical 1 Input

The document contains code snippets from a C++ programming assignment. It includes multiple short programs that take user input, perform basic mathematical calculations like addition, multiplication, finding the square or products of numbers, and outputting the results. The programs demonstrate concepts like input/output, variables, basic math operators and printing output to the screen.

Uploaded by

Ng Siewmin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Week 2 Practical 1 Input

The document contains code snippets from a C++ programming assignment. It includes multiple short programs that take user input, perform basic mathematical calculations like addition, multiplication, finding the square or products of numbers, and outputting the results. The programs demonstrate concepts like input/output, variables, basic math operators and printing output to the screen.

Uploaded by

Ng Siewmin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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