https://www.hackerrank.com/contests/elite-recursion/challenges/recursion-14/problem
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int n,k,t;
void rpat()
{
if(n == t)
return;
printf("%d ",n);
n=n+k;
rpat();
}
void fpat()
{
if(n<=0)
{
rpat();
return;
}
printf("%d ",n);
n=n-k;
fpat();
}
int main() {
scanf("%d%d",&n,&k);
t=n;
fpat();
printf("%d ",n);
return 0;
}
No comments:
Post a Comment