C Program Array With Source Code Example. If you are looking for a C program array example, this C programming tutorial will help you to learn how to write a program for array in C. Just go through this C programming example to learn about arrays in C. we are sure that you will be able to write a C programming for array.
C Program Array
C Program Array – Table of Contents
- What is Array in C Programming?
- Arrays Declaration And Initialization
- C Program Array
- C Program Array – Source Code
- C Program Array – Output
- C Programming Tutorials
What is Array in C Programming?
What is an array in C. An array is a kind of data structure, array is a collection of data that stores fixed number of values of same type. For example: if you want to store some numbers, you can create an array for it and store.
Array Syntax:
int number[10];
Once you declare the array size and array type, you cannot be changed.
Types of Arrays:
There are two types of arrays in C programming.
- Onedimensional arrays
- Multidimensional arrays
Arrays Declarations And Initialization
Arrays Declaration:
datatype arrayname[array size];
Array Example:
int numbers[5];
Here numbers array can hold 5 integer elements, in each field of numbers[0], numbers[1], numbers[2], numbers[3], numbers[4].
Initializing Arrays Elements:
Here are the different ways of initializing array elements:
- int numbers[5] = {5,10,15,20,25};
- int numbres[] = {5,10,15,20,25};
How elements stored in array
mark[0] is equal to 5
mark[1] is equal to 10
mark[2] is equal to 15
mark[3] is equal to 20
mark[4] is equal to 25
C Array Program Example
Learn how to write a program for array in c. Writing an array program in C can be done using various techniques but here in this program, we show how to write a arrays program in c in a proper way. Happy coding.
C Program Array Source Code
You can copy paste the below array program in c compiler to check how the source code work. Or write your own array C Program with the help of this below c program for array.
/* C PROGRAM ARRAY - ARRAYEXAMPLE.C */
// C Program Array to find the average of the numbers #include <stdio.h> int main() { //Array declaration int marks[10], i, n, sum = 0, average; printf("Enter n: "); //Asking user to enter number array size scanf("%d", &n); //Reading array elements for(i=0; i<n; ++i) { printf("Enter number%d: ",i+1); //Asking user to enter array elements scanf("%d", &marks[i]); //Reading array elements sum += marks[i]; } average = sum/n; printf("Average = %d", average); //Printing output return 0; }
C PROGRAM Array – OUTPUT
After you compile and run the above c program array, your C compiler asks you to enter elements for the array to perform the average. After you enter elements, the program will be executed and give output.
Output:
Enter n: 5
Enter number1: 10
Enter number2: 15
Enter number3: 20
Enter number4: 25
Enter number5: 30
Average = 20
C PROGRAMMING TUTORIALS
- Binary Search in C Program Using Recursion
- Bubble Sort in C Using Pointers
- Bubble Sort Program in C Using Recursion
- Bubble Sort Program in C Using Array
- Bubble Sort Program in C Using Function
- Bubble Sort Program in C Using Linked List
- Stack Push Pop Program in C Using Arrays
- Factorial Program in C Using Pointers
- Factorial Program in C Using While Loop
- C Program For Factorial Using For Loop
- Factorial Program in C Using Recursion Function
- C Program To Reverse a String Using Pointers
- C Program To Swap Two Numbers Using Two Variables
- C Program To Swap Two Numbers Using Three Variables
- C Program For Prime Numbers – Check a Number is Prime or Not
- C Program To Reverse a String with Using Function
- C Program to Reverse a String without Using Function
- C Program to Reverse a Sting Using Recursion
- C Program For Palindrome String
- C Program For Palindrome Numbers
- C Program To Reverse a String with Using Function
- C Program To Reverse a String without Using Function
- C Program To Reverse a String Using Recursion