Read OnLine Cpp Program Example



5 - ARRAY
PRAC 5 PRAC 6
//wap to print element using float
#include<iostream.h>
#include<conio.h>
void main()
{
float a[5],i;
clrscr();
a[0]=12.5;
a[1]=23.7;
a[2]=45.4;
a[3]=65.6;
a[4]=23.7;
for (i=4;i>=0;i--)
{
cout<<"\n"<<a[i];
}
getch();
}
-----output------
23.7
65.6
45.4
23.7
12.5
//wap to print element using for loop (scanf)
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i;
clrscr();
cout<<"Enter array element: \n";
for (i=0;i<=4;i++)
{
cout<<"\n Enter element "<<i<<":";
cin>>a[i];
}
for (i=0;i<=4;i++)
{
cout<<"\n Element:"<<i<<"="<<a[i];
}
getch();
}
-------output-----
Enter array element:
Enter element 0:23
Enter element 1:64
Enter element 2:45
Enter element 3:11
Enter element 4:12
Element:0=23
Element:1=64
Element:2=45
Element:3=11
Element:4=12
Previous Next
Download Download