Created
September 12, 2016 01:50
-
-
Save talentwill/f044055edc41e5fd0320e15e9034ceb0 to your computer and use it in GitHub Desktop.
PrintN
This file contains hidden or 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 printN1(int N) | |
| { | |
| for (int i = 1; i <= N; ++i) | |
| { | |
| printf("%d\n", i); | |
| } | |
| } | |
| void printN2(int N) | |
| { | |
| if (N != 0) | |
| { | |
| printN2(N); | |
| printf("%d\n", N); | |
| } | |
| } | |
| void printN3(int c, int N) | |
| { | |
| if (c <= N) | |
| { | |
| printf("%d\n", c); | |
| printN3(c + 1, N); | |
| } | |
| } | |
| int main(int argc, char* argv[]) | |
| { | |
| int N = 0; | |
| printf("Input N:\n"); | |
| scanf("%d", &N); | |
| char opt = *argv[1]; | |
| if (opt == '1') | |
| { | |
| printN1(N); | |
| } | |
| else if (opt == '2') | |
| { | |
| printN2(N); | |
| } | |
| else | |
| { | |
| printN3(1, N); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment