Elective---combi

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Elective---combi as PDF for free.

More details

  • Words: 427
  • Pages: 8
ELECTIVE/COMBINATORICS: #include #include <dos.h> #include <stdio.h> #include <stdlib.h> #define UP 72 #define DOWN 80 int choice; int e[]={1,2,3,4,5,6,7,8,9}, c[9]; int n, r; long int total=1, str[1000][9]; int temp, last, loc, p; int x, y; main() { int page, curp; int m, start; char key='\0'; clrscr(); printf("Permutation and Combination"); printf("\n\n1 Permutation\n(maximum is 8 taken 3!)"); printf("\n2 Combination\n(maximum is 9 taken 9!)"); printf("\n3 Exit"); printf("\n\nEnter number of choice: "); scanf("%d",&choice); clrscr(); if(choice==1) permute(); else if(choice==2) combine(); else if(choice==3) exit(0); else { gotoxy(25,7); scanf("%d",&choice); } clrscr(); key='\0'; start=0; curp=1;

if((total%120)==0) page=total/120; else page=(total/120)+1; for(x=1;x<=61;x+=15) { for(y=1;y<=24;y++) { if(start1) { clrscr(); curp--; } } else if(key==DOWN) { if(curp<page) { clrscr(); curp++; } } start=(curp*120)-120; for(x=1;x<=61;x+=15) { for(y=1;y<=24;y++) { if(start
printf("%d",str[start][m]); start++; } } } } } } permute() { int m; clrscr(); datafeed(); loc=r-1; for(m=0;m
if(e[loc]!=c[p]) findnext(); else if(e[loc]==c[p]) { while(e[loc]==c[p]) { loc--; p--; } sortremain(); moveall(); loc=r-1; p=n-1; } } } datafeed() { /*1*/ gotoxy(1,1); printf("Input value of n: "); scanf("%d",&n); /*2*/ gotoxy(1,2); printf("Input value of r: "); scanf("%d",&r); /*3*/ if(choice==1) { if(n==r) { for(x=1;x<=n;x++) total*=x; gotoxy(1,4); printf("Total permutation: %ld\n",total); } else if(n>r) { for(x=n;x!=(n-r);x--) total*=x; gotoxy(1,4); printf("Total permutation: %ld\n",total); } else if(r>n) { while(n
gotoxy(1,1); printf("Input value of n: "); scanf("%d",&n); gotoxy(1,2); printf("Input value of r: "); scanf("%d",&r); } }

} else if(choice==2) { if(n>r) { for(x=n;x!=(n-r);x--) total*=x; for(x=r;x>0;x--) total/=x; gotoxy(1,4); printf("Total combination: %d\n",total); } else if(r>n) { while(r>n) { gotoxy(1,4); printf("Invalid Input"); gotoxy(1,1); printf("Input value of n: "); scanf("%d",&n); gotoxy(1,2); printf("Input value of r: "); scanf("%d",&r); } } } for(x=0;x
for(x=loc;x<(n-1);x++) e[x]=e[x+1]; e[n-1]=temp; } findlast() { for(x=loc;xc[x]) { temp=c[y]; c[y]=c[x]; c[x]=temp; } } } last=c[n-1]; } sortfirst() { for(y=loc;ye[x]) { temp=e[y]; e[y]=e[x]; e[x]=temp; } } } } findnext() { int ctr=0; if(choice==1) { temp=e[loc];

for(x=(loc+1);xe[loc] && ctr==0) { e[loc]=e[x]; e[x]=temp; ctr++; } } last=e[n-1]; } else if(choice==2) { for(x=(loc+1);xe[x]) { temp=e[y]; e[y]=e[x]; e[x]=temp; } } } } moveall() { int z, ctr=0; for(x=(loc+1);x
ctr++; } } for(x=loc;x