(b)WAP to find smallest and largest numbers in a given array using pointer.
==> Code goes like this :
#include <stdio.h>
int main() {
int a[10],size,*p,max,min,i;
printf("\n Enter array size: ");
scanf("%d",&size);
printf("\n Enter %d element of array: ",size);
for (int i = 0; i <size ; ++i) {
scanf("%d",&a[i]);
}
p=a;
max=a[0],min=a[0];
for (int i = 0; i < size; ++i) {
if (*p>max)
{
max=*p;
}
if (*p<min)
{
min=*p;
}
p++;
}
printf("\nLargest number =%d\t smallest number= %d",max,min);
return 0;
}
Output:
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Find largest and smallest element of array using pointer - C
5:05 PM
array
,
array in c
,
C Programs
,
Finding smallest and largest element of array using pointer in C
,
largest & smallest element
,
pointer
,
pointer in c
Edit
0 comments:
Post a Comment