add to array c code example
Example 1: sum of array in c
#include <conio.h>
int main()
{
int a[1000],i,n,sum=0;
printf("Enter size of the array : ");
scanf("%d",&n);
printf("Enter elements in array : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
for(i=0; i<n; i++)
{
sum+=a[i];
}
printf("sum of array is : %d",sum);
return 0;
}
Example 2: c assign array
model :
type arrayName[arraySize] = {value1, value2, ..., valuearraySize};
example :
double balance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0};
for multi dimensional arrays :
type arrayName[size1][size2] = {{value11, value12, ..., value1size2}, {value21, value22, ..., value2size2}, ..., {valuesize11, valuesize12, ..., valuesize1size2}};
example :
int a[3][4] = {
{0, 1, 2, 3} ,
{4, 5, 6, 7} ,
{8, 9, 10, 11}
};