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

Q1: Write a program in C++ that takes a number as an input and prints its

multiplication table up to 10.

Solution:
#include <iostream.h>
using namespace std;
int main ()
{
int num;
cout << "Enter Number To Find Multiplication table ";
cin >> num;
for (int a = 1; a <= 10; a++)
{
cout << num << " * " << a << " = " << num * a << endl;
}
return 0;
}

e|1
Q2: Write a program in C++ that takes input and swap two numbers.

Solution:
#include < iostream.h >
using namespace std;
int main ()
{
int a;
cout << "Enter value for a: ";
cin >> a;
int b;
cout << "Enter value for b: ";
cin >> b;
cout << "Value before Swap" << endl;
cout << "The value of a is: " << a << endl;
cout << "The value of b is: " << b << endl;
int c = a;
a = b;
b = c;
cout << "Value after Swap" << endl;
cout << "The value of a is: " << a << endl;
cout << "The value of b is: " << b << endl;
return 0;
}

e|2
Q3: Write a program in C++ that takes input and print the sum of two
numbers.

Solution:
#include < iostream.h >
using namespace std;
int main()
{
int a;
cout<<"Enter the Value of a: ";
cin>>a;
int b;
cout<<"Enter the Value of b: ";
cin>>b;
int sum =a+b;
cout<<"The Sum of a and b is: "<<sum;
return 0;
}

e|3

You might also like