IslamicBoard
Experience a richer experience on our mobile app!
View Full Version : Anybody good with programming?
#include <stdio.h> int n_choose_k(int n, int k); int recursion(int n); int recursionk(int k); int recursionnk(int n,int k); int recursionb(int b); int main(int argc, char **argv) { int n, k; scanf("%d %d", &n, &k); printf("There are %d ways to choose %d items from %d distinct items", n_choose_k(n, k), k, n); return 0; } int n_choose_k(int n, int k) { return (recursion(n) / (recursionnk(n,k) * recursionk(k))); } int recursion(int n) { if(n == 1) { return n; } return (n * recursion(n-1)); } int recursionk(int k) { int n=k; return recursion(n); } int recursionnk(int n, int k) { int b=n-k; return recursionb(b); } int recursionb(int b) { int n=b; return recursion(n); }
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main(int argc, char **argv) { int i=0, n=0, o=0, cycle=0, maxcyc=0, maxcycn=0; printf("Enter a number:"); scanf("%d", &n); for(i=1; i<=n; i++) { o = i; cycle = 0; while(o>1) { if(o%2==0) { o /= 2; } else { o = (o * 3) +1; } cycle++; } if(cycle>maxcyc) { maxcyc = cycle; maxcycn = i; } } printf("Longest cycle was generated by %d which caused %d cycles to occur", maxcycn, maxcyc); return 0; }
void order(int A[], int usedup){ int j, temp, didswap; while(didswap){ didswap=0; for(j=0; j<(usedup-1); j++){ if(A[j] >= A[j+1]){ temp = A[j]; A[j] = A[j+1]; A[j+1] = temp; didswap=1; } } } return; }
Experience a richer experience on our mobile app!