Skip to content

Instantly share code, notes, and snippets.

@talentwill
Created September 12, 2016 01:50
Show Gist options
  • Select an option

  • Save talentwill/f044055edc41e5fd0320e15e9034ceb0 to your computer and use it in GitHub Desktop.

Select an option

Save talentwill/f044055edc41e5fd0320e15e9034ceb0 to your computer and use it in GitHub Desktop.
PrintN
#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