Write a program that inputs ages of different persons in an array and counts the number of persons that have ages between 65 and 80.
So let’s Write Code:
Let’s build logic First:
Algorithm for code:
- Start
- Declare an array capible of holding 5 integer values.
- Input Integers in Array.
- Store Integer into the array.
- Print the stored integer.
- Finish Program
Code:
Write a program that inputs the ages of different persons in an array and counts the number of persons that have ages between 65 and 80.
#include<iostream>
using namespace std;
main()
{
int age[10], n, count = 0;
for(n = 0; n<=9; n++)
{
cout<<"Enter age of person no. "<<n+1<<" ? ";
cin>>age[n];
}
for(n = 0; n<=9; n++)
if(age[n] >=65 && age[n]<=80)
count++;
cout<<"\nThe number of persons that have ages between 65 and 80 = "<<count;
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/