| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Wed Jan 09, 2008 2:19 pm Post subject: I made a simple C application |
|
|
not long ago, i started learning C (i have a book)
here's my fifth (i think) application, don't laugh
| Code: | #include <stdio.h>
void main(void)
{
int a,b,c;
printf("Insert first number: \n");
scanf("%d",&a);
printf("Insert second number: \n");
scanf("%d",&b);
printf("Insert third number: \n");
scanf("%d",&c);
if ((a>b) & (a>c))
printf("First number is bigger");
else
if ((b>a) & (b>c))
printf("Second number is bigger");
else
if ((c>b) & (c>a))
printf("Third number is bigger");
else
if ((a=b) || (a=c) || (b=a) || (b=c) || (c=a) || (c=b))
printf("All numbers are equal");
} |
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Wed Jan 09, 2008 3:01 pm Post subject: |
|
|
Very nice.
But the last if could be better: | Code: | if ((a==b) && (b==c))
printf("All numbers are equal"); |
Edit: * fixed syntax.
Last edited by HolyBlah on Thu Jan 10, 2008 2:47 am; edited 1 time in total |
|
| Back to top |
|
 |
Aikos Cheater
Reputation: 0
Joined: 26 Nov 2007 Posts: 47
|
Posted: Thu Jan 10, 2008 2:40 am Post subject: |
|
|
| Dont you use == instead of = when you are checking for equality?
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jan 10, 2008 2:42 am Post subject: |
|
|
| Aikos wrote: | | Dont you use == instead of = when you are checking for equality? |
Lol, yes
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Thu Jan 10, 2008 2:46 am Post subject: |
|
|
| Aikos wrote: | | Dont you use == instead of = when you are checking for equality? | wops, my bad.
Didn't touch C for like a 64 month.
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Thu Jan 10, 2008 2:52 am Post subject: |
|
|
| Aikos wrote: | | Dont you use == instead of = when you are checking for equality? |
That use of = is not always incorrect, he could have been setting some variables and then testing them, for example:
| Code: |
FILE *fp;
if ((fp = fopen("a.txt", "r")) != NULL)
{
//fp is valid, we can use it
fclose(fp);
}
|
_________________
|
|
| Back to top |
|
 |
benlue Moderator
Reputation: 0
Joined: 09 Oct 2006 Posts: 2142
|
Posted: Thu Jan 10, 2008 2:59 am Post subject: |
|
|
| That's true appalsap but i doubt he is actually testing them.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Jan 10, 2008 5:44 am Post subject: |
|
|
i checked wikipedia for C operators, and it said that:
|| Logical OR
& AND
etc..
what's the diff between, & and && ? or = and == ?
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
btw, when you add a library (.h, header) file, what's the diffrent between:
<windows.h> and "windows.h" ?
@ HolyBlah:
yeah, i was thinking there would be a way to optimise that block, thanks
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Thu Jan 10, 2008 6:31 am Post subject: |
|
|
'=': Assigning operator:
'&', '|', '^': Binary commands:mean: | Code: |
&:
8 = 1000
9 = 1001
17 = 10001
|:
9 = 1001
10 = 1010
11 = 1011
^(Xor):
9 = 1001
10 = 1010
3 = 0011 |
'&&', '||':Compare operator:
| Code: | command = ((5+3==9)||(3+1==4)).
(5+3=9) = False.
(3+1=4) = True.
((5+3==9)||(3+1==4)) = True.
command = ((5+3==9)&&(3+1==4)).
(5+3=9) = False.
(3+1=4) = True.
((5+3==9)&&(3+1==4)) = False. |
|
|
| Back to top |
|
 |
nox Expert Cheater
Reputation: 0
Joined: 09 Apr 2007 Posts: 227 Location: brooklyn
|
Posted: Thu Jan 10, 2008 7:09 am Post subject: |
|
|
you could have reduced the amount of code in the last line by using previous indication but good work either way
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Jan 11, 2008 5:16 am Post subject: |
|
|
| Kaspersky wrote: | btw, when you add a library (.h, header) file, what's the diffrent between:
<windows.h> and "windows.h" ? | The path where does the compiler look for the file.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Jan 11, 2008 7:54 am Post subject: |
|
|
| Jani wrote: | | Kaspersky wrote: | btw, when you add a library (.h, header) file, what's the diffrent between:
<windows.h> and "windows.h" ? | The path where does the compiler look for the file. |
can you give me an example ?
like <windows.h> or "X:\windows.h" ?
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Jan 11, 2008 4:57 pm Post subject: |
|
|
| Kaspersky wrote: | | like <windows.h> or "X:\windows.h" ? |
" " : Look in the projects folder. Then if not found look in the includes.
< > : Skip the project folder and just look in the includes.
Also, your lack of {}s is annoying. A lot of people try and shorten up their code by not using them, but generally it is more readable to leave them in. There are a few situations however where you would be better off without them.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Jan 12, 2008 3:57 am Post subject: |
|
|
| Flyte wrote: | | Kaspersky wrote: | | like <windows.h> or "X:\windows.h" ? |
" " : Look in the projects folder. Then if not found look in the includes.
< > : Skip the project folder and just look in the includes.
Also, your lack of {}s is annoying. A lot of people try and shorten up their code by not using them, but generally it is more readable to leave them in. There are a few situations however where you would be better off without them. |
very nice explained, thanks
and yeah, about the {} the book didn't toled me (yet) to use {} in this assignment
|
|
| Back to top |
|
 |
|