1.

write a c program to intialize one dimensional array and access the elements and print the output in the display

Answer»

#include  int main() {    int arr[5], i;      for(i = 0; i < 5; i++)    {        printf("ENTER a[%d]: ", i);        scanf("%d", &arr[i]);    }      printf("\nPrinting elements of the ARRAY: \n\n");      for(i = 0; i < 5; i++)    {        printf("%d ", arr[i]);    }      // signal to operating system program ran fine    return 0; }-------------------------------------output: Enter a[0]: 11 Enter a[1]: 22 Enter a[2]: 34 Enter a[3]: 4 Enter a[4]: 34  PRINTING elements of the array:  11 22 34 4 34Explanation:u can initialize an array in c by first declaring the data type eg: int or float or char...., followed by the array name of ur choiceeg:int my_array[100]here 100 is the size of the arrayu can get the individual elements by accessing the array the same way u declared iteg: my_array[0]  will give u the first element as indexing starts with 0if u try to use an invalid index the compiler will give u a "garbage' valuehope this helps



Discussion

No Comment Found