C Program Array With Source Code Example

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.

  1. Onedimensional arrays
  2. 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:

  1. int numbers[5] = {5,10,15,20,25};
  2. 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

  1. Binary Search in C Program Using Recursion
  2. Bubble Sort in C Using Pointers
  3. Bubble Sort Program in C Using Recursion
  4. Bubble Sort Program in C Using Array
  5. Bubble Sort Program in C Using Function
  6. Bubble Sort Program in C Using Linked List
  7. Stack Push Pop Program in C Using Arrays
  8. Factorial Program in C Using Pointers
  9. Factorial Program in C Using While Loop
  10. C Program For Factorial Using For Loop
  11. Factorial Program in C Using Recursion Function
  12. C Program To Reverse a String Using Pointers
  13. C Program To Swap Two Numbers Using Two Variables
  14. C Program To Swap Two Numbers Using Three Variables
  15. C Program For Prime Numbers – Check  a Number is Prime or Not
  16. C Program To Reverse a String with Using Function
  17. C Program to Reverse a String without Using Function
  18. C Program to Reverse a Sting Using Recursion
  19. C Program For Palindrome String
  20. C Program For Palindrome Numbers
  21. C Program To Reverse a String with Using Function
  22. C Program To Reverse a String without Using Function
  23. C Program To Reverse a String Using Recursion

Leave a Reply

Your email address will not be published. Required fields are marked *