Dynamic memory allocation.
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void
main()
{
int
n,i,*s;
clrscr();
printf("\n\t\t
Dynamic memory allocation\n");
printf("\nEnter
the no. of student:- ");
scanf("%d",&n);
s=(int
*)malloc(n*2);
for(i=0;i<n;i++)
{
printf("\nEnter
marks of %d student: ",i+1);
scanf("%d",&s[i]);
}
printf("\n\n
Marks of students are:\n");
for(i=0;i<n;i++)
printf("\n\nMarks
of %d student:-%d",i+1,s[i]);
getch();
}
output:
Dynamic
memory allocation
Enter
the no. of student:- 5
Enter
marks of 1 student: 65
Enter
marks of 2 student: 87
Enter
marks of 3 student: 85
Enter
marks of 4 student: 36
Enter
marks of 5 student: 88
Marks
of students are:
Marks
of 1 student:-65
Marks
of 2 student:-87
Marks
of 3 student:-85
Marks
of 4 student:-36
Marks of 5 student:-88
No comments:
Post a Comment