Write a C program to find both the largest and smallest number of an array of integers.
SOURCE CODE:
/*Program to Find Largest and Smallest among set of Numbers*/
#include<stdio.h>
void main()
{
int a[20],n,i,largest,smallest;
clrscr();
printf("Enter number of elements:");
scanf("%d",&n);
printf("\nEnter %d elements:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
largest=a[0];
smallest=a[0];
for(i=0;i<n;i++)
{
if(largest<=a[i])
largest=a[i];
if(smallest>=a[i])
smallest=a[i];
}
printf("\nLargest number is %d",largest);
printf("\nSmallest number is %d",smallest);
}
OUTPUT:
SOURCE CODE:
/*Program to Find Largest and Smallest among set of Numbers*/
#include<stdio.h>
void main()
{
int a[20],n,i,largest,smallest;
clrscr();
printf("Enter number of elements:");
scanf("%d",&n);
printf("\nEnter %d elements:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
largest=a[0];
smallest=a[0];
for(i=0;i<n;i++)
{
if(largest<=a[i])
largest=a[i];
if(smallest>=a[i])
smallest=a[i];
}
printf("\nLargest number is %d",largest);
printf("\nSmallest number is %d",smallest);
}
OUTPUT:
Write C programs illustrating call by value concept.
SOURCE CODE:
/*Program to implement call by value*/
void call_by_val(int,int);
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a,b values:");
scanf("%d%d",&a,&b);
printf("\n::Before function calling::\n a=%d \t b=%d",a,b);
call_by_val(a,b);
printf("\n::After function calling::\n a=%d \t b=%d",a,b);
}
void call_by_val(int a,int b)
{
int c;
c=a;
a=b;
b=c;
printf("\n::In function::\n a=%d \t b=%d",a,b);
}
OUTPUT:
Write a C program illustrating call by reference concept.
SOURCE CODE:
/*Program to implement call by reference*/
void call_by_ref(int*,int*);
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a,b values:");
scanf("%d%d",&a,&b);
printf("\n::Before function calling::\n a=%d \t b=%d",a,b);
call_by_ref(&a,&b);
printf("\n::After function calling::\n a=%d \t b=%d",a,b);
}
void call_by_ref(int *a,int *b)
{
int c;
c=*a;
*a=*b;
*b=c;
printf("\n::In function::\n a=%d \t b=%d",*a,*b);
}
OUTPUT: