logo codesdope
Level 1
1.
Length and breadth of a rectangle are 5 and 7 respectively. Write a program to calculate the area and perimeter of the rectangle.
Answer
#include <iostream>
int main()
{
	using namespace std;
	cout << "Area is " << 5*7 << endl;
	cout << "Perimeter is " << 2*(5+7) << endl;
	return 0;
}									

2.
Write a program to input the value of the radius of a circle from keyboard and then calculate its perimeter and area.
Answer
#include <iostream>
int main()
{
	using namespace std;
	int radius;
	cout << "Enter radius of circle" << endl;
	cin >> radius;
	cout << "Perimeter is " << 2*3.14*radius << endl;
	cout << "Area is  " << 3.14*radius*radius << endl;
	return 0;
}
									

3.
Write a program to enter a 4 digit number from the keyboard. Add 8 to the number and then divide it by 3. Now, the modulus of that number is taken with 5 and then multiply the resultant value by 5. Display the final result.
Answer
#include <iostream>
int main()
{
	using namespace std;
	cout << (((8+2345)/3)%5)*5 << endl;
	return 0;
}

									

4.
Now, solve the above question using assignment operators (eg. +=, -=, *=).

5.
Enter two numbers from keyboard. Write a program to check if the two numbers are equal.
Answer
#include <iostream>
int main()
{
	using namespace std;
	int x,y;
	cin >> x;
	cin >> y;
	cout << (x == y) << endl;
	return 0;
}

									

6.
Write a program to enter the values of two variables 'a' and 'b' from keyboard and then check if both the conditions 'a < 50' and 'a < b' are true.
Answer
#include <iostream>
int main()
{
	using namespace std;
	int b,a;
	cin >> a;
	cin >> b;
	cout << (a < 50 && a < b) << endl;
	return 0;
}
									

7.
Now solve the above question to check if atleast one of the conditions 'a < 50' and 'a < b' is true.
Answer
#include <iostream>
int main()
{
	using namespace std;
	int b,a;
	cin >> a;
	cin >> b;
	cout << (a < 50 || a < b) << endl;
	return 0;
}
									

8.
If the marks of Robert in three subjects are 78,45 and 62 respectively (each out of 100 ), write a program to calculate his total marks and percentage marks.

9.
Write a program to enter the values of two variables from the keyboard and then interchange the values of the two variables. E.g.-
If entered value of x is 5 and y is 10 then
cout <<x << " and " << y
should print 10 and 5.
Answer
#include <iostream>
int main()
{
	using namespace std;
	int x,y,temp;
	cin >> x;
	cin >> y;
	temp = x;    //temp is assigned the value of x
	x = y;       //x is assigned the value of y
	y = temp; 
	cout <<x << " and " << y << endl;
	return 0;
}									

10.
Take input of some length in meter and covert it to feet and inches.

11.
Write a program to convert Fahrenheit into Celsius.

12.
The total number of students in a class are 45 out of which 25 are boys. If 80% of the total students secured grade 'A' out of which 17 are boys, then write a program to calculate the total number of girls getting grade 'A'.
Answer
#include <iostream>
int main()
{
	using namespace std;
	int total, b, g;
	b = 17;
	total = (80*45)/100;  //total students getting grade A
	g = total - b;        //number of girls getting grade A
	cout << "Number of girls getting grade A = " << g << endl;
	return 0;
}
									

Level 2
1.
Write a program to calculate the sum of the first and the second last digit of a 5 digit.
E.g.- NUMBER : 12345
OUTPUT : 1+4=5
Answer
#include <iostream>
int main()
{
	using namespace std;
	int n, first, second, third, forth, fifth, sum;
	n = 23462;
	/*Now we will take out each digit of this number and then finally add the first and the second last digits*/
	first = n/10000;     //first digit
	n = n%10000;
	
	second = n/1000;     //second digit
	n = n%1000;
	
	third = n/100;       //third digit
	n = n%100;
	
	forth = n/10;        //forth digit
	fifth = n%10;        //fifth digit
	
	sum = first + forth;
	cout << "sum : " << sum << endl;
	return 0;
}

									

2.
Take a 4 digit number. Write a program to display a number whose digits are 2 greater than the corresponding digits of the number TAKEN.
For example, if the number which was taken is 5696, then the displayed number should be 7818.

3.
Write a program to calculate the sum of the digits of a 3-digit number.
Number : 132
Output : 6

4.
Write a program to reverse a 3-digit number. E.g.-
Number : 132
Output : 231

Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.