Q:

C program to read and print One Dimensional Array of integer elements

0

C program to read and print One Dimensional Array of integer elements

This program will read and print 10 elements of integer type using One Dimensional Array. To read and print 10 elements we will run loop from index 0 to 9 because first elements stores at index 0 and this index is called base index of the array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Read and Print One Dimensional Array using C Program

/*Program to read and print one dimensional array. */
 
#include <stdio.h>
 
/** funtion :   readArray() 
    input   :   arr ( array of integer ), size 
    to read ONE-D integer array from standard input device (keyboard). 
**/
void readArray(int arr[], int size) 
{ 
    int i =0; 
 
    printf("\nEnter elements : \n"); 
 
    for(i=0; i<size; i++) 
    { 
        printf("Enter arr[%d] : ",i); 
        scanf("%d",&arr[i]); 
    } 
} 
 
/** funtion :   printArray() 
    input   :   arr ( array of integer ), size 
    to display ONE-D integer array on standard output device (moniter). 
**/
void printArray(int arr[],int size) 
{ 
    int i =0; 
 
    printf("\nElements are : "); 
 
    for(i=0; i<size; i++) 
    { 
        printf("\n\tarr[%d] : %d",i,arr[i]); 
    } 
    printf("\n"); 
} 
 
int main() 
{ 
    int arr[10]; 
 
    readArray(arr,10); 
    printArray(arr,10); 
 
    return 0; 
}

Output

    Enter elements : 
    Enter arr[0] : 1 
    Enter arr[1] : 2 
    Enter arr[2] : 3 
    Enter arr[3] : 4 
    Enter arr[4] : 5 
    Enter arr[5] : 6 
    Enter arr[6] : 7 
    Enter arr[7] : 8 
    Enter arr[8] : 9 
    Enter arr[9] : 10 

    Elements are : 
	    arr[0] : 1 
	    arr[1] : 2 
	    arr[2] : 3 
	    arr[3] : 4 
	    arr[4] : 5 
	    arr[5] : 6 
	    arr[6] : 7 
	    arr[7] : 8 
	    arr[8] : 9 
	    arr[9] : 10 

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

One Dimensional Array Programs / Examples in C programming language

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to calculate sum, product of all One Dim... >>
<< C program to print the number of subset whose elem...