ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Home » C programs » C one dimensional array programs

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.

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 

ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.