Wednesday 20 February 2013

Array


//Program for  Array with dynamic size
#include<stdio.h>
int main()
{
int max=100;
char name[20];
int arr[max],size,i,s,s1;
printf("Enter the name:");
scanf("%s",name);
printf("%s\n",name);

printf("\n\t****when size of array is not known earlier***\n");
printf("\nEnter the number of elements in  the array");
scanf("%d",&size);
printf("\n Enter the Elements of the array:\n");
for(i=0;i<size;i++)
{
scanf("%d",&arr[i]);
}

printf("\n The array is: ");
for(i=0;i<size;i++)
{
printf("\t%d",arr[i]);
}
printf("\n");

printf("\n\t**Determining the size of array**\n");
s=sizeof(arr);
s1=sizeof(arr)/sizeof(int);
printf("\n\t**Total memory space required for array of 100 elements**\n");
printf("\n\t %d",s);
printf("\n**number of elements in array**\n");
printf("\n\t%d",s1);


}

No comments:

Post a Comment