6.write for loop that will produce each of the following sequence 2, 4, 6, ….44
5, 7, 9,…...45
The sum of numbers between 2 to 44 inclusive
The sum of the first 20 numbers in the series 1, 4, 7, 10…
7.Re write the following code fragment using one switch statement
if (ch = = ‘E’|| ch= = ‘e’)
cout<<" this is either the value of ‘E’ or ‘e’";
else if (ch = = ‘A’|| ch= = ‘a’)
cout<<" this is either the value of ‘A’ or ‘a’";
else if (ch = = ‘r’|| ch= = ‘i’)
cout<<" this is either the value of ‘i’ or ‘r’";
else
cout<<" Enter the correct choice";
8.Write a C++ program for the following flowchart. N.B Let the user enter the
initial value of X and Y, finaly your program should return the value of X, Y and
Z.
9.If the originally x=2 ,y=1 and z=1, what are the value of x, y, z after executing the
following code?
Switch(x)
{
case 0 : x = 2;
y =3;
case 1 : x =4;
Default:
y = 3;
x = 1;
#include <iostream>
using namespace std;
int main() {
// 1 2 4 8 16
for(int i=2;i<=44;i=i*2){
cout<<i<<" "; }
cout<<"\n";
// 1 2 4 6 10 15
for(int i=5;i<=45;i=i+i){
cout<<i<<" ";
}
return 0; }
Comments
Leave a comment