Created
September 23, 2011 05:05
-
-
Save b-adams/1236776 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int getNumberFromUser(); | |
int main(int argc, char* argv[]) | |
{ | |
int usersNumber; | |
int i; | |
printf("MAIN BEGINS!\n"); | |
//Do the following code ten times | |
for(i=0; i<10; i++) | |
{ | |
usersNumber=getNumberFromUser(); | |
printf("You entered… %d!\n", usersNumber); | |
} | |
printf("MAIN ENDS!\n"); | |
return 0; | |
} | |
int getNumberFromUser() | |
{ | |
int theNumber; | |
return theNumber; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int twice(int n); | |
int doubleOneMultipleTimes(int timesToDouble); | |
int main(int argc, char* argv[]) | |
{ | |
int usersNumber; | |
int twoToTheUsersNumber; | |
printf("Please enter a number:"); | |
scanf("%d",&usersNumber); | |
printf("If you double 1, %d times, you'll get %d.\n", 2, twice(twice(1))); | |
twoToTheUsersNumber = 17; | |
printf("If you double 1, %d times, you'll get %d. I think.\n", | |
usersNumber, twoToTheUsersNumber); | |
return 0; | |
} | |
int twice(int n) { return 2*n; } | |
int doubleOneMultipleTimes(int timesToDouble) | |
{ | |
int theResult; | |
if(timesToDouble<0) theResult=1/doubleOneMultipleTimes(-timesToDouble); | |
else if(timesToDouble==0) theResult=1; | |
else theResult=twice(doubleOneMultipleTimes(timesToDouble-1)); | |
return theResult; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void pause(); | |
int main(int argc, char* argv[]) | |
{ | |
printf("Enter two letters/numbers/symbols, then press enter twice.\n"); | |
printf("That letter is character number: %d\n", getchar()); | |
printf("That letter is character number: %d\n", getchar()); | |
printf("That letter is character number: %d\n", getchar()); | |
printf("That letter is character number: %d\n", getchar()); | |
pause(); | |
printf("And now, for something completely different!\n"); | |
pause(); | |
printf("Platypus.\n"); | |
return 0; | |
} | |
void pause() | |
{ | |
printf("This would be a great time to pause… but how!?\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int afunc(int x, int y); | |
int bfunc(int y, int x); | |
int cfunc(int z, int w); | |
int main(int argc, char* argv[]) | |
{ | |
int x; | |
int y; | |
printf("MAIN BEGINS\n"); | |
x=7; | |
y=11; | |
x=afunc(x,y); | |
y=bfunc(y,x); | |
printf("The answer is %d\n", cfunc(x,y)); | |
printf("MAIN ENDS\n"); | |
return 0; | |
} | |
int afunc(int x, int y) | |
{ | |
int returnme; | |
printf("-> calling afunc(%d, %d)\n", x,y); | |
returnme = x+y; | |
printf("<- afunc(%d, %d) returns %d\n", x,y, returnme); | |
return returnme; | |
} | |
int bfunc(int y, int x) | |
{ | |
int returnme; | |
returnme = cfunc(y,x)*cfunc(x,y); | |
return returnme; | |
} | |
int cfunc(int z, int w) | |
{ | |
return w%z; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAIN BEGINS | |
-> calling afunc(7, 11) | |
<- afunc(7, 11) returns 18 | |
-> calling bfunc(11, 18) | |
-> calling cfunc(11, 18) | |
<- cfunc(11, 18) returns 11 | |
-> calling cfunc(18, 11) | |
<- cfunc(18, 11) returns 7 | |
<- bfunc(11, 18) returns 77 | |
-> calling cfunc(18, 77) | |
<- cfunc(18, 77) returns 5 | |
The answer is 5 | |
MAIN ENDS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment