Sunteți pe pagina 1din 5

Question #1: Write a program that take two numbers and check if first number is cube root of

second. If it is then output the result that look like the following statement, e.g. 8 is cube root of
2.

Solution:
#include <iostream>

using namespace std;

int main()
{

int number, result;


cout << "Enter any number: ";
cin >> number;
cout << "\n Cube Root of "<< number <<" is: " <<result;
}

OUTPUT
Enter any number : 27
Cube root of 27 is: 3

Question #2: Write a program that takes three numbers as input and displays the greatest one.

Solution:
#include <iostream>

using namespace std;

int main()
{
int a,b,c,greatest;
cout<<"Enter three numbers : ";
cin>>a>>b>>c;
greatest=(a>b&&a>c)?a:(b>c)?b : c;
cout<<"Greatest number is "<<greatest;

return 0;
}
Question #3: Read a number and prints its absolute value.
Solution:
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter any number:";
cin>>a;
if(a>0)
cout<<"The absolute value of number is:"<<a;
else
cout<<"The absolute value of number is:"<<-(a);
return 0;
}

Question #4: Read the slopes of two lines and write whether these are parallel or not. If these
are not parallel, determine whether these are perpendicular or not.

Solution:
#include <iostream>
using namespace std;
int checkLines(double slope1, double slope2)
{
if (slope1 = slope2)
{
cout << "\n Your slopes are parallel." << endl;
}
if (slope1*slope2 = -1)
{
cout << "Your slopes are perpendicular." << endl;
}
else
cout << "Your slopes are regularly intersected." << endl;
}
int main()
{
int slope1, slope2;
cout << "\n Please input two slopes of two different lines."<<endl;
cin >> slope1;
cin >> slope2;
checklines(slope1,slope2);
Question #5: Write a program to take two numbers from user and display their sum.

Solution:
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<< "\nEnter first number : ";
cin>>a;
cout<<"\nEnter second number : ";
cin>>b;
c=a+b;
cout<<"\nThe Sum is : "<<c;

return 0;
}

Question #6: Take three numbers as input from user and calculate their average.

Solution:
#include <iostream>

using namespace std;

int main()
{
int a, b ,c,sum;
float average;
cin>>a>>b>>c;
sum = a+b+c;
cout<<"The sum of 3 numbers is:"<<sum<<endl;
average =sum/3;
cout<<"The average of 3 numbers is:"<<sum<<endl;
return 0;
}
Question #8: Write menu driven program that accept a number and then ask user to enter
choice 1,2 or 3. It then checks the number according to entered choice and outputs the result.
Choice Result
1 Multiple of 3
2 Composite or prime
3 Negative or positive

Solution:
# include <iostream>
using namespace std;
int main()
{
char no;
float num1, num2;

cout << "Enter operator either 1 or 2 or 3 /: ";


cin >> no;

cout << "Enter two operands: ";


cin >> num1 >> num2;

switch(no)
{
case '1':
int res;
for (int i=1; i<=n; i++)
res=i%3==0;
cout<<"the multiple of three is" res;

break;
Question#9: Print the following.
*

***

*****

*******

*********

***********

*************

Solution:
#include <iostream>
using namespace std;

int main()
{
int space, a;
cout << “ENTER NUMBER OF ROWS : ”;
cin>>a;
for(int i = 1 , k = 0; i <= a; ++i; ++space)
{
cout<< “ ”;
}
If (k ! = 2*i-1)
{
cout << “* ”;
+kk;
}

S-ar putea să vă placă și