Read OnLine Cpp Program Example
5 - ARRAY | |
---|---|
PRAC 7 | PRAC 8 |
//wap to print element using for loop #include<iostream.h> #include<conio.h> void main() { int a[5],i; clrscr(); cout<<"Enter array element:"; for (i=4;i>=0;i--) { cout<<"\n Enter element"<<i<<":"; cin>>a[i]; } for (i=4;i>=0;i--) { out<<"\n Element:"<<i<<"="<<a[i]; } getch(); } ------output------ Enter array element: Enter element4:23 Enter element3:455 Enter element2:45 Enter element1:42 Enter element0:23 Element:4=23 Element:3=455 Element:2=45 Element:1=42 Element:0=23 |
//wap to print adding element #include<iostream.h> #include<conio.h> void main() { int a[5],ans; clrscr(); a[0]=23; a[1]=12; a[2]=45; a[3]=25; a[4]=34; ans=a[0]+a[1]+a[2]+a[3]+a[4]+a[5]; cout<<ans; getch(); } -------output-------- 139 |
Previous | Next |
Download | Download |