1#include <stdio.h>#include <conio.h>long factorial (int n){ if (n==0) return 1; else return (n * factorial(n-1)); //recursion}void main(){ int number; long fact; printf("Enter a number: "); scanf("%d", &number); fact = factorial(number); printf("The factorial of %d is %ld!\n", number, fact); getch();}
1/*C program to convert number from decimal to binary*/
2
3#include <stdio.h>
4
5int main()
6{
7 int number,cnt,i;
8 int bin[32];
9
10 printf("Enter decimal number: ");
11 scanf("%d",&number);
12
13 cnt=0; /*initialize index to zero*/
14 while(number>0)
15 {
16 bin[cnt]=number%2;
17 number=number/2;
18 cnt++;
19 }
20
21 /*print value in reverse order*/
22 printf("Binary value is: ");
23 for(i=(cnt-1); i>=0;i--)
24 printf("%d",bin[i]);
25
26 return 0;
27}