Array

                                                                        Array      
Array is a collection of similar data type element which have save name but distinguish from index number.C# arrays are zero indexed; that is, the array indexes start at zero. Arrays in C# work similarly to how arrays work in most other popular languages There are, however, a few differences that you should be aware of.(reference)

Syntax:-  

int    salary     [100];
data  array name  size 

Initialization:- 

int num [5]={1,5};//or
int num2[5];
num2[0]=13;
num2[1]=14;
num2[2]=15;
num2[3]=16;

With index address it looks like shown below:-
addressarrayvalue
65520num2[0]13
65522num2[1]14
65524num2[2]15
65526num2[3]16

Scaning of array:- 
int arr[10],i;
for(i=0;i<5;i++)
{scanf("%d",&arr[i]);
}

Printing of array:-
 
int arr[10]={1,2,3},i;
for(i=0;i<5;i++){
printf("%d",arr[i]);
}

Example:-program to print sum of array:-
#include<stdio.h>
#include<conio.h>
void main()
{
int sum=0;
int num[10];

for(i=0;i<10;i++){
printf("enter value in array");
scanf("%d",&num[i]);
sum=sum+num[i]; 
}
printf("%d",sum);
getch();
}

Comments

Popular posts from this blog