Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

DS || Pgm 5 || Program to implement dynamic array, find smallest and largest element of the array.

 #include<stdio.h>

#include<stdlib.h>

int main()

{

int i,n,large,small;

int *a =NULL;

printf("\n enter the the number of elements \n");

scanf("%d",&n);

a=(int*)malloc(n*sizeof(int));

printf("\n Intput the arrays elements");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

large=small=a[0];

for(i=1;i<n;i++)

{

if(a[i]>large)

large=a[i];

if(a[i]<small)

small=a[i];

}

printf("\nthe samller elements is %d\n",small);

printf("\nthe larger elements is %d\n",large);

return 0;

}

Post a Comment

0 Comments