Professional Documents
Culture Documents
Write a program to find the sum of all the odd integers in the range of 1 to 100.
Pseudocode
• Using for loop, list the odd numbers between the range of 1 to 100
• Set the limit, i <=99 and the increment, i++
• Find the sum of all odd numbers by assigning i%2!=0 and sum=sum+1
• Display the result
Flowchart
Start
False
Int i = 1
i <=99
True
if (i%2!=0)
Sum=sum + i
i++
End
Source Input
#include<iostream>
int main ()
int sum=0;
if (i%2!=0)
cout<<i<<" ";
sum=sum+i;
cout<<endl;
system ("pause");
return 0;
}
Output
Question 2
Write a program that asks the user to enter a list of integers. The program is to determine the
largest value entered and the number of times it was entered. For example, if the following
series is entered
5 2 15 3 7 15 8 9 5 2 15
it would output that the largest value is 15n and that it was entered 3 times
Pseudocode
Flowchart
Start
i=0
max=0
j=1
i < 10
j++
No
Yes
Display the
max = num largest value
j=1
No
Yes Display the
max = max largest value
i++
End
Source Input
#include<iostream>
int main()
int i = 0;
int max = 0;
int num;
int j = 1;
if ( max == num ) {
j++;
else {
j = 1;
max = num;
} else {
max = max;
i++;
cout << max << " The number of occurance is " << j << " times.";
system ("pause");
return 0;
}
Output
Question 3
Write a program that prints the following patterns separately on below the other. Use for
loops to generate the patterns. All asterisks should be printed by a cout statement in the form
of cout<<”*”
a) Pseudocode
Using nested loop, for the outer loop, set the value of i = 0
Set the limit i < 11 and its increment, ++i
For the inner loop, set the value j = 1
Set the limit j <= 1 and its increment, ++j
Print the result in the form of “*”
Flowchart
Start
i=1
i<11
++i
j=1
j<=i
++j
End
Source Input
#include<iostream>
int main ()
int i,j;
cout<<"\n";
cout<<"*";
cout<<endl;
system ("pause");
return 0;
Output
b) Pseudocode
• Using nested loop, for the outer loop, set the value of i = 10
• Set the limit i >=1 and its increment, --i
• For the inner loop, set the value j = 1
• Set the limit j <= 1 and its increment, ++j
• Print the result in the form of “*”
Flowchart
Start
i=10
i >=1
--i
j=1
j<=i
++j
End
Source Input
#include<iostream>
int main ()
int i,j;
cout<<"\n";
cout<<"*";
cout<<endl;
system ("pause");
return 0;
}
Output
c) Pseudocode
Using nested loop, for the outer loop, set the value of i = 10
Set the limit i >0 and its increment, i--
For the inner loop, set the value j = 0
Set the limit j > 1 and its increment, j--
Print the result in the form of “(j <= i ? "*" : " " )”
Flowchart
Start
i = 10
i>0
i --
j=0
j >0
j--
End
Source Input
#include<iostream>
int main ()
int i,j;
cout<<" \n";
cout<<endl;
system ("pause");
return 0;
}
Output
d) Pseudocode
Using nested loop, for the outer loop, set the value of i = 1
Set the limit i <= 10 and its increment, i++
For the inner loop, set the value j = 10
Set the limit j >= 1 and its increment, j--
Print the result in the form of “(j <= i ? "*" : " " )”
Flowchart
Start
i=1
i < = 10
i ++
j = 10
j >= 1
j--
End
Source Input
#include<iostream>
int main ()
int i,j;
cout<<"\n";
cout<<endl;
system ("pause");
return 0;
}
Output