QUESTION 1
change the if....else statements below to switch.....case statements:
#include
main()
{
int nom A,nom B,Selection,Value;
cout<<"enter 2 numbers:";
cin>>nomA >>nomB;
cout<<"1.addition";
cout<"2.subtraction";
cout<<"3.multiply";
cout<<"4.division";
cin>>selection;
{
if (selection ==1)
{value =nomA + nomB;}
else if (selection ==2)
{value =nomA - nomB;}
else if (selection ==3)
{value =nomA * nomB;}
else if (selection ==4)
{value =nomA / nomB}
else
cout<<"invalid selection";}
<<"the value is:"<
#include
main()
{
int nom A,nom B,Selection,Value;
cout<<"enter 2 numbers:";
cin>>nomA >>nomB;
cout<<"1.addition";
cout<"2.subtraction";
cout<<"3.multiply";
cout<<"4.division";
cin>>selection;
switch (selection)
{case 1:value=nomA + nomB;break
case 2:value=nomA - nomB;break
case 3:value=nomA * nomB;break
case 4:value=nomA / nomB;break
default cout<<"invalid selection";
cout <<"the value is"<
}
return 0;
}
QUESTION 2
change for loop statement below to while loop.
#include
main()
{
int i,power 2;
for (i=1;i<=9;i++)
{
power 2= i * i;
cout<<" "<
}
}
ANSWER
#include
main()
{
int i,power 2;
while
i = 1;
while ( i <=9 )
{
power 2 = i * i;
cout <<" "<< i << "power 2" << power 2;
i++;
}
}
QUESTION 3
write a program that input 2 numbers.compare and display only the biggest number.if the numbers are same,display the numbers are same
ANSWER
#include
main()
{
int num1,num2;
cout<<"enter 2 numbers:";
cin >> nomA >> nomB;
//if...else statement
if (num 2 > num 1)
{ cout <<"num 2 is bigger than num 1";}
else if (num 2 == num 1)
{ cout <<"num 2 is same as num 1";}
else
{ cout <<"invalid selection";}
return 0;
}
QUESTION 4
write a programming using for loop that recive pricess of 3 products.calculate the price that must be paid after 10% discount is given to every customer.
ANSWER
#include
main()
{
int x,price,total discount;
for (x=1;x<4;x++)
{
cout<<"price [ "<< x << " ] : ";
cin>>price;
}
total + price;
}
cout<<"total = " << total;
discount = total * 0.01;
cout<<"discount = "<
return 0;
}
QUESTION 5
what is the output for the following program segment
I) int x=20;
for (int i=5;i<=x;i++)
{
cout <<1;
i = 1 + 4;
}
ANSWER:
5
10
15
20
II) Int mul = 1;
do
{
mul = mul * 2;
cout <<"the mul is :"<
mul+++;
}
while (mul<10)
ANSWER
1
3
7
0 comments:
Post a Comment
thanks for comment..