Looping Structure - Seatwork

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Algorithm and C++ problem

Looping Structure

Directions: Write the equivalent algorithm and the C++ Program to the following problems.

1. A program and algorithm that prints the sum of number of series.

Ex:

12345678910

Sum: 55

2. A Program and algorithm where it shows whether a number is a Palindrome or not.

Ex.

Enter Number: 575

The number is a Palindrome

3. A program and algorithm where to find the average of 5 numbers using a loop and array.

Ex.

Enter five numbers:


9 8 7 66 5

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

// input values by the user


cout << "Enter five numbers: ";
cin >> Number1 >> Number2 >> Number3 >> Number4 >> Number5;

// calculating the average value


Average = (Number1 + Number2 + Number3 + Number4 + Number5)/5;

// 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/

You might also like