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