Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Assignment 1 – Practice Questions

Marks = 10
Practice the following questions on the compiler and paste the screen shot in
the document. Submit this document on LMS.
Note: Do not Copy Past

Task 1: Input three integer values from keyboard into variables a, b and c.
Code:
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cout << "Enter a value of a:";
cin >> a;
cout << "Enter a value of b:";
cin >> b;
cout << "Enter a value of c:";
cin >> c;
return 0;
}
Output:

Task 2: Assign the product of variables b and c to a as entered by the user.


Code:
#include <iostream>
using namespace std;

int main()
{
int a, b, c;
cout << "Enter integer a and b values :";
cin >> a >> b; c = a * b;
cout << "a = " << a << ", b= " << b << endl;
cout << "c = " << c << endl;
return 0;
}
Output
Task 3: Write a program that calculates the square of a number entered by the
user and displays output as below.
Value Square

4 16

Code:
#include <iostream>

using namespace std;

int main() {

int num, sqr;

cout << "Enter a number \n";


cin >> num;

sqr = num * num;

cout << " Square of a number is " << sqr;

return 0;
}
Output:
Task 4: What would be the output
int i=6, j=2;
cout<<i<<endl;
cout<<i++<<endl;
cout<<++i<<endl;
cout<<j++<<endl;
cout<<++i-j<<endl;
cout<<i-j--<<endl;
output:

**************************Best of Luck****************************

You might also like