Write a 'C' Program to accept 'n' numbers from user and find out the maximum element out of them by using dynamic memory allocation.


#include

void main()
{
    int *ptr,i,j,n,max;
    clrscr();
    printf("HOW MANY NUMBERS U WANT ::> ");
    scanf("%d",&n);
    ptr = (int *)malloc(sizeof(int) * n);
    printf("\nENTER %d ELEMENT::>\n",n);
    for(i = 0 ; i < n ; i++)
    {
        scanf("%d",&ptr[i]);
    }
    max = ptr[0];
    for(i = 0 ; i < n ; i++)
    {
        if(ptr[i] > max)
        {
            max = ptr[i];
        }
    }
    printf("MAXIMUM ::> %d",max);
    getch();
}
/*OUTPUT::
HOW MANY NUMBERS U WANT ::> 5

ENTER 5 ELEMENT::>
56 89 45 61
23
MAXIMUM ::> 89
HOW MANY NUMBERS U WANT ::> 10

ENTER 10 ELEMENT::>
1 9 4 5 7 6 3 2 9 8
MAXIMUM ::> 9
*/
Write a 'C' Program to accept 'n' numbers from user and find out the maximum element out of them by using dynamic memory allocation. Write a 'C' Program to accept 'n' numbers from user and find out the maximum element out of them by using dynamic memory allocation. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.