int binomialCoefficient(int n, int k){ int nfac; int kfac; int nkfac; if(n < 0 || k < 0) return -1; nfac = faktorial(n); kfac = faktorial(k); nkfac = faktorial(n-k); return nfac/(kfac * nkfac); }
int poradi_na_permutace (int poradi, int * permutace, int len) { int current; int i, j; /* visited[i] == 1, jestli uz se vyskytlo cislo (i+1) v permutaci */ static int * visited = (int *)0x80000000; int faktor = faktorial (len); for (i = 0; i < len; ++i) visited[i] = 0; if (poradi > faktor)/* permutace delsi nez pozadovana delka */ return 0; for (i = 0; i < len; i++) { faktor /= (len - i); current = ((poradi - 1) / faktor) + 1; poradi = ((poradi - 1) % faktor) + 1; permutace[i] = current; /** * Najdeme (current)-te dosud nepouzite cislo */ for (j = 0;; j++) { if (visited[j] == 0) current--; if (current == 0) break; } j++; /* protoze cislujeme od jednicky, ale visited je cislovane od 0 (0 znamena 1, 1 znamena 2 atd.) */ permutace[i] = j; visited[j-1] = 1;/* (j-1) - viz poznamka u deklarace visited nahore */ } return 1; }
int main(void) { unsigned int n; scanf("%u!", &n); printf("%llu\n", faktorial(n)); return 0; }
void main() { clrscr(); int angka,x; cout << "_____________________________________________________\n"; cout << "\nNama Program : Menghitung faktorial by Address \n"; cout << "Pembuat : Irvan Abdurrahman | 4510210003\n"; cout << "Update : 22 Maret 2011 \n"; cout << "_____________________________________________________\n"; do { cout << "\n==MENU PILIHAN== \n"; cout << "1. Input Nilai \n"; cout << "2. Menghitung Faktorial \n"; cout << "3. Keluar \n"; cout << "\nMasukkan pilihan : "; cin >> angka; switch(angka) { case 1: cout << "Input Nilai : "; cin >> x; break; case 2: cout << "Hasil faktorial : "; cout << faktorial(&x) << endl; break; case 3:cout <<"Terima Kasih\n"; break; } } while(angka!=3); getch(); }
int faktorial(int cislo) { if(cislo == 0) { return 1; } if(cislo <= 2) { return cislo; } return cislo * faktorial(cislo-1); }
void bezier(int x[],int y[],int n){ int faktorial(int); int sumx; int sumy; int i; float t; //cout << faktorial(n-i); for(t = 0.01;t<1;t+=0.001){ //cout << t << endl; sumx = 0; sumy = 0; for(i = 0;i<=n;i++){ float pangkat; if(n-i == 1){ pangkat = 1; }else{ pangkat = pow(1-t,n-i); } sumx += faktorial(n) / faktorial(i) / faktorial(n-i) * pangkat * pow(t,i) * x[i]; sumy += faktorial(n) / faktorial(i) / faktorial(n-i) * pangkat * pow(t,i) * y[i]; //cout << x[i] << " " <<faktorial(n) / faktorial(i) / faktorial(n-i) * pangkat * pow(t,i) * y[i] << endl; } //cout <<sumx<< " " << sumy; putpixel(sumx,sumy,WHITE); } }
int permutace_na_poradi (int * permutace, int len) { int i, j, compared; int poradi = 0; int faktor = faktorial (len); for (i = 0; i < len; i++) { faktor /= (len - i); compared = permutace[i]; for (j = 0; j < i; j++) { if (permutace[i] > permutace[j]) compared--; } compared--; poradi += compared * faktor; } poradi++; return poradi; }
int main(void) { printf("%d! = %d\n", 5, faktorial(5)); return 0; }
int main (int argc, char *argv[]) { int poradi, poradi_zpetne; int i; int * permutace; int digits = 0; int power_of_ten = 1; int permutace_len; int permutace_count; char * tail; if (argc == 1) permutace_len = 9; else if (argc == 2) permutace_len = (int) strtou32 (argv[1]); else { writes (stderr, "Pouziti: prec <delka permutace>\n"); exit(); return 1; } permutace_count = faktorial (permutace_len); /** * Spocteme pocet cislic v desitkovem zapisu poctu permutaci, * abychom mohli zarovnat vypis */ //while (permutace_count > power_of_ten) { // power_of_ten *= 10; // digits++; //} /** * Test konzistence indexovani permutaci hrubou silou. * * Projdeme vsechna poradi, dekodujeme permutaci, vytiskneme permutaci, * permutaci zpet zakodujeme na poradi a porovname toto poradi * s puvodnim. Jestli se lisi, tiskneme na konci radku "!!!FAIL!!!", * jestli ne, tak "OK". */ permutace = (int *) 0x90000000; for (poradi = 1; poradi <= permutace_count; poradi++) { writes (stderr, "Permutace "); writei (stderr, poradi); writes (stderr, ": "); poradi_na_permutace (poradi, permutace, permutace_len); PRINT_INT_ARRAY (permutace, permutace_len, i); poradi_zpetne = permutace_na_poradi (permutace, permutace_len); if (poradi_zpetne == poradi) writes (stderr, " OK"); else { writes (stderr, " FAILED, permutace_na_poradi vratila "); writei (stderr, poradi_zpetne); } writes (stderr, "\n"); } exit(); return 0; }
UINT32 faktorial(UINT32 n) { if (n==0) return 1; else return n*faktorial(n-1); }
/** * @brief Sestaveni celeho okna kalkulaci a pozicovani objektu */ MainWindow::MainWindow(QWidget *parent) : /* nize je napozicovany kazdy jednotlivy objekt kalkulacky, a take spusteni signalu */ QMainWindow(parent) { this->setWindowTitle("Kalkulačka Vořežpruti"); lcd = new QLCDNumber(10, this); lcd -> setGeometry(QRect(QPoint(50,50), QSize(200, 50))); clear_button = new QPushButton("C",this); clear_button -> setGeometry(QRect(QPoint(200,300), QSize(50,50))); connect(clear_button, SIGNAL(released()), this, SLOT(clear())); napoveda_button = new QPushButton("?", this); napoveda_button -> setGeometry(QRect(QPoint(125,400), QSize(50,50))); connect(napoveda_button, SIGNAL(released()), this, SLOT(napoveda())); rovno_button = new QPushButton("=", this); rovno_button -> setGeometry(QRect(QPoint(50,350), QSize(200,50))); connect(rovno_button, SIGNAL(released()), this, SLOT(rovno())); scitani_button = new QPushButton("+", this); scitani_button -> setGeometry(QRect(QPoint(50,100), QSize(50,50))); connect(scitani_button, SIGNAL(released()), this, SLOT(scitani())); nasobeni_button = new QPushButton("x", this); nasobeni_button -> setGeometry(QRect(QPoint(150,100), QSize(50,50))); connect(nasobeni_button, SIGNAL(released()), this, SLOT(nasobeni())); deleni_button = new QPushButton("/", this); deleni_button -> setGeometry(QRect(QPoint(200,100), QSize(50,50))); connect(deleni_button, SIGNAL(released()), this, SLOT(deleni())); odcitani_button = new QPushButton("-", this); odcitani_button -> setGeometry(QRect(QPoint(100,100), QSize(50,50))); connect(odcitani_button, SIGNAL(released()), this, SLOT(odcitani())); nula_button = new QPushButton("0", this); nula_button -> setGeometry(QRect(QPoint(50,300), QSize(50,50))); connect(nula_button, SIGNAL(released()), this, SLOT(nula())); jedna_button = new QPushButton("1", this); jedna_button -> setGeometry(QRect(QPoint(50,250), QSize(50,50))); connect(jedna_button, SIGNAL(released()), this, SLOT(jedna())); dva_button = new QPushButton("2", this); dva_button -> setGeometry(QRect(QPoint(100,250), QSize(50,50))); connect(dva_button, SIGNAL(released()), this, SLOT(dva())); tri_button = new QPushButton("3", this); tri_button -> setGeometry(QRect(QPoint(150,250), QSize(50,50))); connect(tri_button, SIGNAL(released()), this, SLOT(tri())); ctyri_button = new QPushButton("4", this); ctyri_button -> setGeometry(QRect(QPoint(50,200), QSize(50,50))); connect(ctyri_button, SIGNAL(released()), this, SLOT(ctyri())); pet_button = new QPushButton("5", this); pet_button -> setGeometry(QRect(QPoint(100,200), QSize(50,50))); connect(pet_button, SIGNAL(released()), this, SLOT(pet())); sest_button = new QPushButton("6", this); sest_button -> setGeometry(QRect(QPoint(150,200), QSize(50,50))); connect(sest_button, SIGNAL(released()), this, SLOT(sest())); sedm_button = new QPushButton("7", this); sedm_button -> setGeometry(QRect(QPoint(50,150), QSize(50,50))); connect(sedm_button, SIGNAL(released()), this, SLOT(sedm())); osm_button = new QPushButton("8", this); osm_button -> setGeometry(QRect(QPoint(100,150), QSize(50,50))); connect(osm_button, SIGNAL(released()), this, SLOT(osm())); devet_button = new QPushButton("9", this); devet_button -> setGeometry(QRect(QPoint(150,150), QSize(50,50))); connect(devet_button, SIGNAL(released()), this, SLOT(devet())); tecka_button = new QPushButton(".", this); tecka_button -> setGeometry(QRect(QPoint(100,300), QSize(50,50))); connect(tecka_button, SIGNAL(released()), this, SLOT(tecka())); faktorial_button = new QPushButton("!", this); faktorial_button -> setGeometry(QRect(QPoint(200,150), QSize(50,50))); connect(faktorial_button, SIGNAL(released()), this, SLOT(faktorial())); mocnina_button = new QPushButton("^", this); mocnina_button -> setGeometry(QRect(QPoint(200,200), QSize(50,50))); connect(mocnina_button, SIGNAL(released()), this, SLOT(mocnina())); odmocnina_button = new QPushButton("sqrt", this); odmocnina_button -> setGeometry(QRect(QPoint(200,250), QSize(50,50))); connect(odmocnina_button, SIGNAL(released()), this, SLOT(odmocnina())); negate_button = new QPushButton("+/-", this); negate_button -> setGeometry(QRect(QPoint(150,300), QSize(50,50))); connect(negate_button, SIGNAL(released()), this, SLOT(negate())); }