Saturday, May 21, 2011

Program C Mencari Nilai MAX dan MIN

#include <stdio.h>
#include <conio.h>

int bil[10];
int main ()
{
    int i, n, max, min;
    printf("jumlah bilangan yang akan di inputkan: ");
    scanf("%d", &n);
    printf("Masukkan bilangan\n");
   
    for(i=0; i<n; i++)
    {
         printf("bil[%d]: ", i+1);
         scanf("%d", &bil[i]);
    }
   
    max = bil[0];
    min = bil[0];
    for( i=0; i<3; i++)
    {
         if ( bil[i] > max) max= bil[i];
         if ( bil[i] < min) min= bil[i];
    }
   
    printf("Max = %d\n", max);
    printf("Min = %d", min);   
   
    printf("\n\n====================================================\n");
    printf("\t\tVera Suryaningsih\n\tCopyright spirit221.blogspot.com\n");
    printf("\n====================================================\n");
    getch();
    return 0;
}

Output

0 comments:

Post a Comment