/*write a c program to accept n number from user and find out the maximum
element out of them by dynamic memory allocation */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *p,n,i,j,max;
clrscr();
printf("\nenter how many number :");
scanf("%d",&n);
p=(int*)malloc(n * sizeof(int));
printf("\nenter the element:\n");
for(i=0;i<n;i++)
scanf("%d",p+i);
max=*(p+0);
for(i=1;i<n;i++)
{
if(max<*(p+i))
max=*(p+i);
}
printf("maximum number:%d",max);
getch();
}
/*
enter how many number :5
enter the element:
13
45
7
9
6
maximum number:45
*/
No comments:
Post a Comment