How one dimensional array is initialized?

The initialization can be done in two ways:
1. Initialization at design level : In this type of initialization of array the data values are stored in to the array at the time of array declaration. 
Example : 
int array[]={1,5,2,30,50};

2. Initialization at run time :  In this type of initialization of array, means to input data values in to the array at the time of execution of the program. 

Example using for loop: 
int array[10];
for(i=0;i<10;i++)
scanf(“%d”,&array[i]);

Example using do-while loop: 
int array[10];
i=0;
do
{
scanf(“%d”,&array[i]);
i++;
}
while(i<10);

Example using while loop: 
int array[10];
i=0;
while(i<10)
{
scanf(“%d”,&array[i]);
i++;
}

How to output the elements of one dimensional array?
To print elements of an array a for loop, do-while or while loop are used.

Example using for loop: 
int array[10];
for(i=0;i<10;i++)
printf(“%d\n”,array[i]);

Example using do-while loop: 
int array[10];
i=0;
do
{
printf(“%d\n”,array[i]);
i++;
}
while(i<10);

Example using while loop: 
int array[10];
i=0;
while(i<10)
{
printf(“%d\n”,array[i]);
i++;
}



Thanks
Mukesh Rajput


Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: