Go Back   Computer Forums > Welcome To Computer Forums .org > Social Lounge | Off Topic
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-25-2008, 01:20 AM   #1
Golden Master
 
Thelis's Avatar
 
Join Date: Mar 2007
Posts: 5,410
Send a message via AIM to Thelis Send a message via MSN to Thelis Send a message via Yahoo to Thelis
Default Had an array in C homework... will make you laugh.

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);

}
__________________

Thelis is offline   Reply With Quote
Old 03-25-2008, 01:30 AM   #2
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: Had an array in C homework... will make you laugh.

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

{edit} Is there a punkbuster for compilers?
__________________

__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 03-25-2008, 01:35 AM   #3
Golden Master
 
Thelis's Avatar
 
Join Date: Mar 2007
Posts: 5,410
Send a message via AIM to Thelis Send a message via MSN to Thelis Send a message via Yahoo to Thelis
Default Re: Had an array in C homework... will make you laugh.

They call it Microsoft Visual Studio, but instead of punks, it busts people.
Thelis is offline   Reply With Quote
Old 03-25-2008, 10:48 AM   #4
Golden Master
 
Tommy Boy's Avatar
 
Join Date: Jul 2004
Location: USA
Posts: 8,463
Send a message via Yahoo to Tommy Boy
Default Re: Had an array in C homework... will make you laugh.

Quote:
Originally Posted by Thelis View Post
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.
__________________
When all else fails...Ham Radio!

I still have the same old HP DV9700T laptop I've had for years...still kickin'
Tommy Boy is offline   Reply With Quote
Old 03-25-2008, 11:04 AM   #5
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: Had an array in C homework... will make you laugh.

Quote:
Originally Posted by Tommy Boy View Post
I don't get it.
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.
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 03-25-2008, 04:15 PM   #6
Fully Optimized
 
Š88's Avatar
 
Join Date: May 2005
Posts: 4,775
Send a message via MSN to Š88
Default Re: Had an array in C homework... will make you laugh.

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.
__________________
Killing under the cloak of war is no different than murder

Kein Alkohol ist auch keine Lösung!
Š88 is offline   Reply With Quote
Old 03-25-2008, 04:35 PM   #7
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: Had an array in C homework... will make you laugh.

Dude arrays are the bomb. Only 2nd to pointers...
JogaBonito1502 is offline   Reply With Quote
Old 03-25-2008, 05:32 PM   #8
Golden Master
 
Tommy Boy's Avatar
 
Join Date: Jul 2004
Location: USA
Posts: 8,463
Send a message via Yahoo to Tommy Boy
Default Re: Had an array in C homework... will make you laugh.

Quote:
Originally Posted by celegorm View Post
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
__________________
When all else fails...Ham Radio!

I still have the same old HP DV9700T laptop I've had for years...still kickin'
Tommy Boy is offline   Reply With Quote
Old 03-25-2008, 06:15 PM   #9
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: Had an array in C homework... will make you laugh.

Arrays and hash arrays will become extremely important as you progress. Congrats on finding the work around though1
__________________

__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 05:45 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0