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