1) Program To Find Factorial of A Given Number
1) Program To Find Factorial of A Given Number
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1;
else
{
for(i=1; i<=n; ++i)
{
factorial *= i; // factorial = factorial*i;
}
printf("Factorial of %d = %llu", n, factorial);
}
return 0;
}
------------------------------------------------------------------------------------
2) C program to add digits of a number
#include <stdio.h>
int main()
printf("Enter an integer\n");
scanf("%d", &n);
t = n;
while (t != 0)
remainder = t % 10;
t = t / 10;
return 0;
--------------------------------------------------------------------------------------
3) Write a c program that prints all multiples of 3between 1 and 50
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("The multiples of 3 between 1 and 50 are :");
for(a=1;a<=50;a++)
{
if(a%3==0)
{
printf("\n%d",a);
}
}
getch();
}
---------------------------------------------------------------------------------------
#include <stdio.h>
int main()
int n, c, k;
scanf("%d", &n);
printf("\n");
return 0;
----------------------------------------------------------------------------------------------------
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
#include <stdio.h>
int main()
{
int rows, coef = 1, space, i, j;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=0; i<rows; i++)
{
for(space=1; space <= rows-i; space++)
printf(" ");
for(j=0; j <= i; j++)
{
if (j==0 || i==0)
coef = 1;
else
coef = coef*(i-j+1)/j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
6) Program to print Binomial coefficient
#include<stdio.h>
#define MAX 10
int main()
{
int n, a, bi_nom;
printf("Mx ");
do
{
a = 0, bi_nom = 1;
printf("%2d", n);
while(a<=n)
{
if(n==0 || a==0)
printf("%4d", bi_nom);
else
{
bi_nom=bi_nom* (n-a+1)/a;
printf("%4d", bi_nom);
}
a=a+1;
}
printf("\n");
n=n+1;
}while(n<=MAX);
printf("----------------------------------------------------------");
}
Sample Output of above program:
Mx 0 1 2 3 4 5 6 7 8 9 10
----------------------------------------------------------
0 1
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1
6 1 6 15 20 15 6 1
7 1 7 21 35 35 21 7 1
8 1 8 28 56 70 56 28 8 1
9 1 9 36 84 126 126 84 36 9 1
10 1 10 45 120 210 252 210 120 45 10 1
----------------------------------------------------------
#include <stdio.h>
int main()
{
int i, n, t1 = 0, t2 = 1, nextTerm;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
Sample Output