How to write C Programs | Array | Malloc | sizeof
#include<stdio.h>
#include<conio.h>
void main()
{
int *a,i,n;
clrscr();
printf("enter the no of elements");
scanf("%d",&n);
a=(int *)malloc(n*sizeof (int));
printf("enter array elements");
for(i=0;i<n;i++)
{
printf("a[%d]=",i);
scanf("%d",a+i);
}
printf("array elements is\n");
for(i=0;i<n;i++)
printf("%5d",*(a+i));
getch();
}
#include<conio.h>
void main()
{
int *a,i,n;
clrscr();
printf("enter the no of elements");
scanf("%d",&n);
a=(int *)malloc(n*sizeof (int));
printf("enter array elements");
for(i=0;i<n;i++)
{
printf("a[%d]=",i);
scanf("%d",a+i);
}
printf("array elements is\n");
for(i=0;i<n;i++)
printf("%5d",*(a+i));
getch();
}
0 comments: