3
7/21/2019 Ncr http://slidepdf.com/reader/full/ncr5695d10b1a28ab9b0294e5f9 1/3 ncr #include<stdio.h> #include<conio.h> int fact(int x); void main()  {  int n,r,ncr;  clrscr();  printf("\nEnter the value of N and R\n");  scanf("%d%d",&n, &r); p  ncr=fact(n)/(fact(r)*fact(n-r));  printf("\nOur answer is:: %d",ncr);  getch();  } int fact(int x)  {  int f=1,i;  if(x==0)  {  return(f);  }  else  {  for(i=1;i<=x;i++)  {  f=f*i;  }  return(f);  }  } /* Calculate Permutation and Combination (nCr and nPr)  Using Function */ #include<stdio.h> #include<conio.h> void main() {  int n,c,r,ncr,npr;  long int fact( int ); /* function Prototype */  clrscr();  printf("Enter the Value of n and r, n must be n>r :\n");  scanf("%d%d",&n,&r);  ncr= fact(n)/fact(n- r);  npr= fact(n)/(n*fact (n-r));  printf("NCR = %d\n",ncr);  printf("NPR = %d\n",npr);  getch(); }  long int fact( int x)  {  long int f=1; Page 1

Ncr

Embed Size (px)

DESCRIPTION

a

Citation preview

Page 1: Ncr

7/21/2019 Ncr

http://slidepdf.com/reader/full/ncr5695d10b1a28ab9b0294e5f9 1/3

ncr#include<stdio.h>

#include<conio.h>

int fact(int x);

void main()

  {

  int n,r,ncr;

  clrscr();

  printf("\nEnter the value of N and R\n");

  scanf("%d%d",&n,&r); p

  ncr=fact(n)/(fact(r)*fact(n-r));

  printf("\nOur answer is:: %d",ncr);

  getch();

  }

int fact(int x)

  {

  int f=1,i;

  if(x==0)

  {

  return(f);

  }

  else

  {

  for(i=1;i<=x;i++)

  {

  f=f*i;

  }

  return(f);

  }

  }

/* Calculate Permutation and Combination (nCr and nPr)  Using Function */#include<stdio.h>#include<conio.h>void main(){  int n,c,r,ncr,npr;  long int fact( int ); /* function Prototype */  clrscr();  printf("Enter the Value of n and r, n must be n>r :\n");  scanf("%d%d",&n,&r);  ncr= fact(n)/fact(n-r);  npr= fact(n)/(n*fact(n-r)); 

printf("NCR = %d\n",ncr);  printf("NPR = %d\n",npr);  getch();}  long int fact( int x)  {  long int f=1;

Page 1

Page 2: Ncr

7/21/2019 Ncr

http://slidepdf.com/reader/full/ncr5695d10b1a28ab9b0294e5f9 2/3

ncr  int i;  for(i=1;i<=x;i++)  f=f*i;  return(f);

  }

#include<stdio.h>#include<conio.h>void main(){  int fact,i,n;  fact = 1;  printf("Enter the number\t");  scanf("%d" , &n);  for(i = 1; i <= n; i++)  {  fact = fact*i;  }  printf("Factorial of %d is %d", n , fact);  getch();}

#include<stdio.h> 

int main() {  int num, temp, sum = 0, rem; 

printf("\nEnter number for checking Armstrong : ");  scanf("%d", &num); 

temp = num; 

while (num != 0) {  rem = num % 10;  sum = sum + (rem * rem * rem);  num = num / 10;  } 

if (temp == sum)  printf("%d is Amstrong Number", temp);  else  printf("%d is Amstrong Number", temp); 

return (0);}

#include<stdio.h> int main() {  char str1[30], str2[30];  int i; 

printf("\nEnter two strings :");  gets(str1);  gets(str2); 

i = 0;  while (str1[i] == str2[i] && str1[i] != '\0')  i++;  if (str1[i] > str2[i])  printf("str1 > str2");  else if (str1[i] < str2[i])  printf("str1 < str2");  else  printf("str1 = str2"); 

return (0);}

#include <stdio.h>int main(){  char s1[100], s2[100], i, j;  printf("Enter first string: ");  scanf("%s",s1);

Page 2

Page 3: Ncr

7/21/2019 Ncr

http://slidepdf.com/reader/full/ncr5695d10b1a28ab9b0294e5f9 3/3

ncr  printf("Enter second string: ");  scanf("%s",s2);  for(i=0; s1[i]!='\0'; ++i); /* i contains length of string s1. */  for(j=0; s2[j]!='\0'; ++j, ++i)  {  s1[i]=s2[j];  }  s1[i]='\0';  printf("After concatenation: %s",s1);  return 0;}

Page 3