Question:10
C Program to take input for “N” elements using an array, pass the entire array to a function, display the following:
1. max array element.
2. min array elements.
3. difference between max and min array element.
Sol:
#include <stdio.h>
void show(int *p,int n)
{
int i,ma,mi,d;
ma=*p;
mi=*p;
for(i=0;i<n;i++)
{
printf("%d\n",*p);
//max no
if(*p>ma)
ma=*p;
//min no
if(*p<mi)
mi=*p;
p++;
}
//diff
d=ma-mi;
printf("Max element = %d Min element = %d Diff = %d\n",ma,mi,d);
}
int main()
{
int a[20],i,n;
printf("Enter total elements ");
scanf("%d",&n);
/* input */
for(i=0;i<n;i++)
{
printf("Enter %d element ",i);
scanf("%d",&a[i]);
}
/* function calling */
show(a,n);
/* or */
/* show(&a[0],n); */
return(0);
}
/* Output */ Enter total elements 5 Enter 0 element 36 Enter 1 element 24 Enter 2 element 5 Enter 3 element 98 Enter 4 element 5 36 24 5 98 5 Max element = 98 Min element = 5 Diff = 93
Question:11
C Program to take input for “N” elements using an array, further take input for an element to search, pass the entire array to a function, check and print whether the element is present or not?
Sol:
code
/* Output */
Question:12
C Program to take input for “N” elements using an array, further take input for an element to search , pass the entire array to a function, check and print whether the element is present or not, if present also print its count (Search and Count)?
Sol:
code
/* Output */




