lundi 21 novembre 2016

C Language: Write a program that would take 30 integers and prints the largest number and the smallest number

Write a program that would take 5 integers and prints the largest number and the smallest number

i tried this code

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1, num2, num3, num4, num5;
    int largest;
    int smallest;

    printf ( "\nEnter five integers." );
    printf ( "\nAnd I will give you the smallest and the largest." );

        scanf( "%d%d%d%d%d",  &num1, &num2, &num3, &num4, &num5 );

            if ( num1 >= num2, num3, num4, num5 )
            {
                ( "num1 = largest" );
            }

            if ( num1 <= num2, num3, num4, num5 )
            {
                ( "num1 = smallest" );
            }

            if ( num2 >= num1, num3, num4, num5 )
            {
                ( "num2 = largest" );
            }

            if ( num2 <= num1, num3, num4, num5 )
            {
                ( "num2 = smallest" );
            }

            if ( num3 >= num1, num2, num4, num5 )
            {
                ( "num3 = largest" );
            }

            if ( num3 <= num1, num2, num4, num5 )
            {
                ( "num3 = smallest" );
            }

            if ( num4 >= num1, num2, num3, num5 )
            {
                ( "num4 = largest" );
            }

            if ( num4 <= num1, num2, num3, num5 )
            {
                ( "num4 = smallest" );
            }

            if ( num5 >= num1, num2, num3, num4 )
            {
                ( "num5 = largest" );
            }

            if ( num5 <= num1, num2, num3, num4 )
            {
                ( "num5 = smallest" );
            }

            printf ( "The largest integer is %d.", largest);
            printf ( "The smallest integer is %d.", smallest);

    return 0;
}

but there's somthing wrong!

please can any one help to solve this ? and if we can do this with while loop please explaine

thanks

Aucun commentaire:

Enregistrer un commentaire