Berikut merupakan program untuk mencari nilai terkecil (minimum) dan terbesar (maximum) dalam bahasa C
#include <stdio.h>
#include <conio.h>
int maximum (int, int, int, int, int, int);
int minimum (int, int, int, int, int, int);
int main()
{
int a, b, c, d, e, f;
printf("Masukkan 6 angka : ");
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
printf("maximum : %d\n", maximum(a, b, c, d, e, f));
printf("minimum : %d\n", minimum(a, b, c, d, e, f));
getch();
}
int maximum (int a, int b, int c, int d, int e, int f)
{
int max = a;
if (b > max)
max = b;
if (c > max)
max = c;
if (d > max)
max = d;
if (e > max)
max = e;
if(f > max)
max = f;
return max;
}
int minimum (int a, int b, int c, int d, int e, int f)
{
int min = a;
if (b < min)
min = b;
if (c < min)
min = c;
if (d < min)
min = d;
if (e < min)
min = e;
if (f < min)
min = f;
return min;
}
#include <stdio.h>
#include <conio.h>
int maximum (int, int, int, int, int, int);
int minimum (int, int, int, int, int, int);
int main()
{
int a, b, c, d, e, f;
printf("Masukkan 6 angka : ");
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
printf("maximum : %d\n", maximum(a, b, c, d, e, f));
printf("minimum : %d\n", minimum(a, b, c, d, e, f));
getch();
}
int maximum (int a, int b, int c, int d, int e, int f)
{
int max = a;
if (b > max)
max = b;
if (c > max)
max = c;
if (d > max)
max = d;
if (e > max)
max = e;
if(f > max)
max = f;
return max;
}
int minimum (int a, int b, int c, int d, int e, int f)
{
int min = a;
if (b < min)
min = b;
if (c < min)
min = c;
if (d < min)
min = d;
if (e < min)
min = e;
if (f < min)
min = f;
return min;
}
0 comments:
Post a Comment