Write a Program for printing Factorial of a number in given range

#include<stdio.h> #include<conio.h> into fact ( int x); main ( ) { int i, n; printf (“enter how many factors”); ...

#include<stdio.h>
#include<conio.h>
into fact ( int x);
main ( )
{
int i, n;
printf (“enter how many factors”);
scanf ("%d”, &n);
for ( i =0; i < n; i ++)
{
  printf (“factorial of %d is %d \n",i, fact (i));
}
getch ( );
}

int fact ( int x)
{
int s = 1, i;
for ( i =1; i < =x; i ++)
{
  s =s*i ;
}
return ( s);
}

Out put:

Enter how many factor 5
Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120

Related

Program to Find Largest and Smallest numbers using Arrays

# include <stdio.h> #include<conio.h> main () { int a[10],i,big,small,n; printf (“enter the size of the array”); scanf (“%d, & n); printf (“enter elements in an array”); for ...

Write a program for Sorting of Numbers using Functions & Pointer?

#include<stdio.h> #include<conio.h> void sort(int *,int); void main() { int a[10], i, n; printf(“enter how many elements”); scanf(“%d”, &n); printf(“enter elements”); f...

Write a program for String copy using pointers

#include<stdio.h> #include<conio.h> void strcopy(char *, char *); main() { char s[10], p[10]; printf(“enter a string”); gets(s); strcopy(s, p); puts(p); getch(); } ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item