fork download
  1. #include <stdio.h>
  2. void zigzag(int n){
  3. if(n==0) return;
  4. printf("%d ",n);
  5. zigzag (n-1);
  6. printf("%d ",n);
  7. zigzag(n-1);
  8. printf("%d ",n);
  9. zigzag (n-1);
  10. return;
  11. }
  12. int main(void) {
  13. int n;
  14. printf("Enter the value: \n");
  15. scanf("%d",&n);
  16.  
  17. zigzag(n);
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5312KB
stdin
4
stdout
Enter the value: 
4 3 2 1 1 1 2 1 1 1 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 1 1 4 3 2 1 1 1 2 1 1 1 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 1 1 4 3 2 1 1 1 2 1 1 1 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 1 1 3 2 1 1 1 2 1 1 1 2 1 1 1