w3resource

C Exercises: Read and Print elements of an array

C Array: Exercise-1 with Solution

Write a program in C to store elements in an array and print them.

Sample Solution:

C Code:

#include <stdio.h>  
  
void  main()  
{  
    int arr[10]; 
    int i;  
       printf("\n\nRead and Print elements of an array:\n");
       printf("-----------------------------------------\n");	
  
    printf("Input 10 elements in the array :\n");  
    for(i=0; i<10; i++)  
    {  
	    printf("element - %d : ",i);
        scanf("%d", &arr[i]);  
    }  
  
    printf("\nElements in array are: ");  
    for(i=0; i<10; i++)  
    {  
        printf("%d  ", arr[i]);  
    } 
    printf("\n");	
}

Sample Output:

Read and Print elements of an array:                                                                          
-----------------------------------------                                                                     
Input 10 elements in the array :                                                                              
element - 0 : 1                                                                                               
element - 1 : 1                                                                                               
element - 2 : 2                                                                                               
element - 3 : 3                                                                                               
element - 4 : 4                                                                                               
element - 5 : 5                                                                                               
element - 6 : 6                                                                                               
element - 7 : 7                                                                                               
element - 8 : 8                                                                                               
element - 9 : 9                                                                                               
                                                                                                              
Elements in array are: 1  1  2  3  4  5  6  7  8  9 

Pictorial Presentation:

C Exercises: Read and Print elements of an array

Flowchart:

Flowchart: Read and Print elements of an array

C Programming Code Editor:

Improve this sample solution and post your code through Disqus.

Previous: C Array Exercises Home
Next: Write a program in C to read n number of values in an array and display it in reverse order.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

C Programming - What is the argument for printf that formats a long?

Put an l (lowercased letter L) directly before the specifier.

unsigned long n;
long m;

printf("%lu %ld", n, m);

Ref : https://bit.ly/3dIwfkP