Showing posts with label Part V : Array (program). Show all posts

Array 2 Dimensi

Example 1:
#include <iostream.h>
#include <conio.h>

main()
{

//initial
int array[2][3] = {/*element in row 1*/ {10, 20, 30},/*element in row 2*/{11, 21, 31 }
};
int row,col;

clrscr();

for (row=0;row<2;row++)
{
for (col=0;col<3;col++)
{
cout <<">
}
cout <<"\n\n";
}

getch();
}

Posted in | 1 Comment

Array 1 Dimensi

Example 1:
#include <iostream.h>
#include <conio.h>

main()
{

int x;
int number[ ] = {1,2,3,4,5,6,7,8,9};
char character[ ] = {'H','E','L','L','O'};

clrscr();

for(x=0;x<9;++x)
{
cout <<"\nData [" <<x <<"] = "< number[x];
}
cout<<"\n";

for(x=0;x<5;++x)
{
cout <<"\nData ["<<x<<"] = "<< character[x];
}

getch();
}
Example 2:
#include <iostream.h>
#include <conio.h>

main()
{

int number[3];
char character[3];
int index;

clrscr();

//Number
cout <<"\n****************";
cout <<"\n* INPUT NUMBER *";
cout <<"\n****************";
//input
for(index=0;index<3;index++)
{
cout <<"\nData "<<index+1 <<" = ";
cin >>number[index];
}
cout <<"\n";
//output
for(index=0;index<3;index++)
{
cout <<"\nData ke-"<<index+1 <<"] = " <<number[index];
}

//Character
cout <<"\n*******************";
cout <<"\n* INPUT CHARACTER *";
cout <<"\n*******************";
//input
for(index=0;index<3;index++)
{
cout <<"\nData "<<index+1 <<" = ";
cin >>character[index];
}
cout <<"\n";
//output
for(index=0;index<3;index++)
{
cout <<"\nData "<<index+1 <"] = " <<character[index];
}

getch();
}

Posted in | Leave a comment

Search

Support by Blogger ITN | Converted by LiteThemes.com