UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to study one Dimensional array

C program to study one dimensional array with program, declaration

by Krishna viswambharan


Posted on 21 Aug 2017 Category: C Views: 246

Edited on 23 Aug 2017


 

C program to study one dimensional array (1 D array)

In this section we will learn to work with arrays.

Array is a collection of data with similar data type.  Instead of declaring the elements individually we can declare it as an array . so we can say that array contains contiguous memory location. The lowest address contains the first element , i.e., array[0] contains the first element and the highest address contains the last element.

The array in C language can be declared as

datatype  array name[size of array]

if we want to declare an array of 10 numbers we can initialize the array in the following way:-

int number[10]

Here is a simple program which shows how to declare, read and access array elements

#include <stdio.h>
#include <conio.h>
void main()
{	
	int  num[50] // declare array
	int sum=0,n,I;
	printf(“Enter the array limit:”);  
	scanf(“%d”,&n);    
	for(i=0;i<n;i++)
	{
		printf(“ Enter the number :”);
		scanf(“%d”,&num[i]);   // read array elements
	}
	for(i=0;i<n;i++)
	{
		sum=sum+num[i];  //calculating the sum of array elements
	}
	printf(“ the total sum of the above numbers is %d”,sum);
	getch();     
}



Leave a Comment:


Advertisement