Q:

C Program To Find Largest And Smallest Number Among N Numbers

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program To Find Largest And Smallest Number Among N Numbers (Simple Way)
  • C Program To Find Largest And Smallest Number Among N Numbers Using Function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program To Find Largest And Smallest Number Among N Numbers Using Pointer

Program -:

//C Program To Find Largest and Smallest  among n Numbers

#include<stdio.h>
void  main()
{
    int i,*ptr, n,a[100],larg,small;

    printf("Enter How many number you want?:\n") ;
    scanf("%d",&n) ;

    printf("Enter %d numbers\n",n) ;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]) ;
    }
    ptr = &a[0];
    larg= *ptr;
    for(i=0;i<n;i++,*ptr++)
    {
        if(*ptr>larg)
        {
            larg=*ptr;
        }
    }
    ptr = &a[0];
    small= *ptr;
    for(i=0;i<n;i++,*ptr++)
    {
        if(*ptr<small)
        {
            small=*ptr;
        }
    }
    printf("Largest Number is %d \n",larg);
    printf("Smallest Number is %d",small);
}

Output -:

Enter How many number you want?:
3
Enter 3 numbers
1
2
3

Largest Number is 3
Smallest Number is 1

C Program To Find Largest And Smallest Number Among N Numbers Using Function

Program -:

//C Program To Find Largest and Smallest  among n Numbers

#include<stdio.h>
void sl(int n)
{
   int i,*ptr,a[100],larg,small;

    printf("Enter  numbers\n") ;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]) ;
    }
    ptr = &a[0];
    larg= *ptr;
    for(i=0;i<n;i++,*ptr++)
    {
        if(*ptr>larg)
        {
            larg=*ptr;
        }
    }
    ptr = &a[0];
    small= *ptr;
    for(i=0;i<n;i++,*ptr++)
    {
        if(*ptr<small)
        {
            small=*ptr;
        }
    }
    printf("Largest Number is %d \n",larg);
    printf("Smallest Number is %d ",small);
}
void  main()
{
    int n;

    printf("Enter How many number you want?:\n") ;
    scanf("%d",&n) ;
    sl(n);
    return 0;
}

Output -:

Enter How many number you want?:
3
Enter 3 numbers
11
22
33

Largest Number is 33
Smallest Number is 11

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Find Area of Circle... >>
<< C Program To Find Largest And Smallest of Three Nu...