NPTEL | Week 0: Assignment 3 Question 3 Introduction to Programming in C (14 Sep- 06 Nov) 2020.



        Introduction to Programming in C       



Assignment 3_Question 3:


Write a C program to list all the factorial numbers less than or equal
to an input number n.

A number N is called a factorial number if it is the factorial of a
positive integer. For example, the first few factorial numbers are

   1, 2, 6, 24, 120, ...

*Note* - We do not list the factorial of 0.

Input
-----
A positive integer, say n.

Output
------
All factorial numbers less than or equal to n.
PROGRAM:

#include<stdio.h>

int factorial(int f)
{
  if(f==1)
    return 1;
  else
    return f*factorial(f-1);
  
}

int main()
{

 int n,l=1,g=2;
  
  scanf("%d",&n);
   
  while(n>=l)
  {
    printf("%d ",l);
    l=factorial(g);
    g++;
  };
  
  return 0;
  
}
  
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100%  correct solutions.

1 comment:

  1. Can you please post Assignments for Week 4 and 5 as well. I am getting error every time. So would really appreciate your help.

    ReplyDelete

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages