Showing posts with label Given Number. Show all posts
Showing posts with label Given Number. Show all posts

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

How to Write a c program to find out NCR factor of given number in C Programming ?


#include<stdio.h>
int main(){
  int n,r,ncr;
  printf("Enter any two numbers->");
  scanf("%d %d",&n,&r);
  ncr=fact(n)/(fact(r)*fact(n-r));
  printf("The NCR factor of %d and %d is %d",n,r,ncr);
  return 0;
}
 int fact(int n){
  int i=1;
  while(n!=0){
      i=i*n;
      n--;
  }
  return i;
 }

C Program to Find NCR Of A Given Number Program

How to write a C Program to Find NCR Of A Given Number in C Programming Language ?

Solution For C Program :

/*C Program to Find NCR Of A Given Number Program*/

#include <stdio.h>
void main()
{
int n, r;
float NCR(int,int);
int Factorial(int n);
printf("\nEnter value for n and r : ");
scanf("%d%d", &n, &r);
printf("\nThe NCR = %0.2f", NCR(n, r));
}
float NCR(int n, int r)
{
int factorial(int);
return((float)factorial(n) / ((float)factorial(n - r) * (float)factorial(r)));
}
int factorial(int n)
{
int k, fact;
for(k = 1, fact = 1; k <= n; k++)
fact = fact * k;
return(fact);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Find Maximum Of Given Numbers

How to write a C Program To Find Maximum Of Given Numbers in C Programming Language ?


Solution For C Program :

/*C Program To Find Maximum Of Given Numbers*/

#include <stdio.h>
void main()
{
void max_three(int,int,int);
int a,b,c;
printf("\nEnter any Three Integers : ");
scanf("%d%d%d", &a, &b, &c);
max_three(a, b, c);
}
void max_three(int x, int y, int z)
{
int d;
if(x > y)
d = x;
else
d = y;
if(d > z)
printf("\nMaximum of Three Numbers : %d", d);
else
printf("\nMaximum of Three Numbers : %d", z);
return;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Reverse A Given Number

How to write a C Program to reverse a given number in C Programming Language ?

Solution For C Program:

/*C Program To Reverse A Given Number*/

#include<stdio.h>
void main()
{
int num, right_digit;
printf("\nEnter The Number : ");
scanf("%d", &num);
printf("\nThe Reverse of %d is : ", num);
while(num != 0)
{
right_digit = num % 10;
printf("%d", right_digit);
num = num / 10;
}
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable