## Monday, August 31, 2015

### C Programs on flow control statements (if, switch, loop, break and continue)-4

2015 & 2016 Batch Freshers Registration Link

C Program to Find Factorial of a Number

main()
{
int i, num, fact = 1;
printf("Enter a number”);
scanf("%d", &num);

for (i = 1; i <= num; i++)
fact = fact * i;

printf("Factorial of %d = %d\n", num, fact);
}

C program to Generate Multiplication Table

main()
{
int i, num;
printf("Enter a number”);
scanf("%d", &num);

for (i = 1; i <= 10; i++)
printf(“%d * %d= %d”,num,i,num*i);

}

C program to calculate the Power of a Number

main()
{
int i, base,exp, power = 1;
printf("Enter base and exponent ”);
scanf("%d %d", &base, &exp);

for (i = 1; i <= exp; i++)
power = power * base;

printf(" %d  power  %d is :%d\n", base,exp,power);

}

Write a c program to find out NCR factor of given number

main()
{

printf(“Enter n and r values”);
scanf(“%d %d”,&n,&r);

printf("%ld ",factorial(n)/(factorial(r)*factorial(n-r));
}

long factorial(int n)
{
int c;
long int result =1;
for(c=1;c<=n;c++)
result=result * c;
return result;
}