Professional Documents
Culture Documents
Looping Structure - Seatwork
Looping Structure - Seatwork
Looping Structure - Seatwork
Looping Structure
Directions: Write the equivalent algorithm and the C++ Program to the following problems.
Ex:
12345678910
Sum: 55
Ex.
3. A program and algorithm where to find the average of 5 numbers using a loop and array.
Ex.
Sum = 95
Average = 19
Answers:
Problem No. 1:
The Flowchart P
C++ Program:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int series;
int sum_of_series=0;
int numbers=10;
for(series=1;series<=numbers;series++)
{
sum_of_series= sum_of_series + series;
cout<<series;
}
cout<<"\nSum: "<<sum_of_series;
getch();
}
Problem No. 2:
C++ Program:
#include<iostream>
using namespace std;
int main()
{
int num,r,sum=0,t;
cout<<"enter number"<<endl;
cin>>num;
t=num;
do
{
r=num%10;
sum=sum*10+r;
num=num/10;
}
while(num!=0);
if(t==sum)
{
cout<<"The number is a palindrome:";
}
else
cout<<"Number is not palidrome:";
}
Problem No. 3:
C++ Program
#include<iostream>
using namespace std;
// main function
int main()
{
// variables to store input values
double Number1, Number2, Number3, Number4, Number5;
double Average; // to store result
// show result
cout << "Average = " << Average << endl;
return 0;
}
Links:
https://t4tutorials.com/palindrome-program-in-c-c-c-plus-plus-cpp-with-flow-chart/
https://t4tutorials.com/c-program-to-find-average-of-5-numbers/
https://t4tutorials.com/program-to-print-sum-of-number-of-series-in-c-plus-plus-cppc-and-c-with-
flowchart/