Arrays
Array are used to store more than one data values in a single variable.
Examples
Write a program to add ten integers.
- #include<iostream.h>
- int main()
- {
- int a[10],b,c;
- for(b=0;b<10;b++)
- {
- cout<<" Enter a number"<<b+1<<" = ";
- cin>>a[b];
- }
- c=0;
- for(b=0;b<=10;b++)
- c=c+a[b];
- cout<<" Sum"<<" = "<<c;
- system("pause");
- return 0;
- }
Reverse Shape
- #include<iostream.h>
- int main()
- {
- int a[10],b,c;
- for(b=0;b<10;b++)
- {
- cout<<" Enter a number "<<b+1<<" = ";
- cin>>a[b];
- }
- for(b=9;b>=0;b––)
- cout<<" \n "<<a[b];
- system("pause");
- return 0;
- }
Write a program to find the largest of ten integers
- #include<iostream.h>
- int main()
- {
- int a[10],b,m;
- for(b=0;b<10;b++)
- {
- cout<<" Enter a number "<<b+1<<" = ";
- cin>>a[b];
- }
- m=a[0];
- for(b=1;b<10;b++)
- if(m<a[b])
- m=a[b];
- cout<<"\n\n\n\t\t The largest number is = "<<m;
- system("pause");
- return 0;
- }
Write a program to find the smallest of ten integers
- #include<iostream.h>
- int main()
- {
- int a[10],b,m;
- for(b=0;b<10;b++)
- {
- cout<<" Enter a number "<<b+1<<" = ";
- cin>>a[b];
- }
- m=a[0];
- for(b=1;b<10;b++)
- if(m>a[b])
- m=a[b];
- cout<<"\n\n\n\t\t The smalest number is = "<<m;
- system("pause");
- return 0;
- }
Write a program to find the smallest and largest of ten integers
- #include<iostream.h>
- int main()
- {
- int a[10],b,m;
- for(b=0;b<10;b++)
- {
- cout<<" Enter a number "<<b+1<<" = ";
- cin>>a[b];
- }
- m=a[0];
- for(b=1;b<10;b++)
- if(m>a[b])
- m=a[b];
- cout<<"\n\n\n\t\t The smalest number is = "<<m;
- m=a[0];
- for(b=1;b<10;b++)
- if(m<a[b])
- m=a[b];
- cout<<"\n\n\n\t\t The greatest number is = "<<m;
- system("pause");
- return 0;
- }
Write a program to accept the choice that how many value are checked in one time
- #include<iostream.h>
- int main()
- {
- int a[10],b,m,c;
- cout<<" In how many value do you want check = ";
- cin>>c;
- for(b=0;b<c;b++)
- {
- cout<<"\n Enter a number "<<b+1<<" = ";
- cin>>a[b];
- }
- m=a[0];
- for(b=1;b<c;b++)
- if(m>a[b])
- m=a[b];
- cout<<"\n\n\t\t\t The smallest is = "<<m;
- m=a[0];
- for(b=1;b<c;b++)
- if(m<a[b])
- m=a[b];
- cout<<"\n\n\t\t\t The largest is = "<<m;
- system("pause");
- return 0;
- }