C++ Program/Code to input the ages of all the students & print only those whose age is greater than 18 years

Leave a Comment
//In this program, the number of the students will be asked from user & stored in an array, and
//selectively will print those ages who are above 18

#include<iostream>                            //For Input/Output Stream Related Functions
#include<conio.h>                              //For Console Input/Output function like clrscr & getche
using namespace std;                         //Using the "standard" namespace of iostream class
void main()
{
clrscr();                                               //For clearing the screen
int a[100],n;
cout<<"\nEnter no. of the student::";
cin>>n;                                               //Number of students entered by the user
for(int i=0;i<n;i++)
{
cout<<"\nEnter The Age:";
cin>>a[i];                                           //The age of students are entered
}
cout<<"’nThe age of students more than 18 years:";
for(int i=0;i<n;i++)
{
if(a[i]>18)
cout<<a[i]<<"\t";                             //Selectively printing those ages who are above 18
}

getche();                                             //To exit the program after an user's keystroke
}

0 comments: