Had an array in C homework... will make you laugh.

Thelis

Golden Master
Messages
5,410
So, I had to write a program that finds out the minimum of three numbers using arrays... Well, I didn't feel like arraying, so I found a way around it.

Code:
#include <stdio.h>

/*Yo, what be up in da professor hizzou!?*/

main (void)

{
    int n1, n2, min12, n3;
    printf ("Enter the first number:");
    scanf ("%d", &n1);
    printf ("Enter the second number:");
    scanf ("%d", &n2);
    printf ("Enter the third number:");
    scanf ("%d", &n3);

if (n1==n2 and n1==n3) printf ("The numbers are the same.");
else if (n1<=n2 && n1<=n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n1);
    else if (n1==n2 and n1<n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n1);
        else if (n1==n2 and n1>n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n3);
else if (n2<=n1 && n2<=n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n2);
else if (n3<=n1 && n3<=n2) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n3);
else if (n1==n2 and n1<n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n1);

}
 
CHEATER! Arrays = god. They are so useful as programs get harder.

{edit} Is there a punkbuster for compilers?
 
They call it Microsoft Visual Studio, but instead of punks, it busts people.
 
So, I had to write a program that finds out the minimum of three numbers using arrays... Well, I didn't feel like arraying, so I found a way around it.

Code:
#include <stdio.h>

/*Yo, what be up in da professor hizzou!?*/

main (void)

{
    int n1, n2, min12, n3;
    printf ("Enter the first number:");
    scanf ("%d", &n1);
    printf ("Enter the second number:");
    scanf ("%d", &n2);
    printf ("Enter the third number:");
    scanf ("%d", &n3);

if (n1==n2 and n1==n3) printf ("The numbers are the same.");
else if (n1<=n2 && n1<=n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n1);
    else if (n1==n2 and n1<n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n1);
        else if (n1==n2 and n1>n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n3);
else if (n2<=n1 && n2<=n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n2);
else if (n3<=n1 && n3<=n2) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n3);
else if (n1==n2 and n1<n3) printf ("The minimum number between %d, %d and %d is %d.", n1, n2, n3, n1);

}
I don't get it.
 
your solution, Thelis, actually makes more sense and is more practical. The assignment or whatever it is should have been to find the minimum number in amongst at least 10 numbers then arrays would have been more necessary.

Since there are only 3 numbers to compare I would have written it in the exact same way.
 
basically, he didn't use an array. Arrays are basically one variable that can hold multiple things of data. All he did was use separate variables.
Ah, well I don't know anything about programming so thats why I didn't get it.....lol
 
Arrays and hash arrays will become extremely important as you progress. Congrats on finding the work around though1
 
Back
Top Bottom