i done C last year and i've 4gotten most of it, but basically the idea is to create an Array containing the 4 digits.
and then print Array[i] where i = rand(1-4)
thet rick is to check if previous numbers are the same as teh randomly generated combination, to do that you'd store each generated random number in a new array and compare the current combination with previous combinatons.
i'd love to translate that into actual code 4u.. but i've just4goten alot of it! maybe if i get a sec i'll look into it insh
The thing is, random numbers are not a guaranteed way of getting those results, and even so, it could take an infinite number of tries to get it right.
I'm sure this can be done with either a recursive function or with several nested loops, but the complexity of this problem is just too much for my mind.
What I have is an array, int arr[]={3,5,3,7}, and I want to print all combinations somehow...
skywalker yeh ur right, i know its a lazy way but hey... theoretically ti works, plus when ur dealin with 2,3 or possibly 4 digits.. you could *possibly* get away with it.
but... i have done a few things b4 with numbers that may be of help?
Here's a combination program i wrote last year.. The issue is, this one tells you how many combinations you can make, but it won't spit out the combinations themselves..
Code:
#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);
}
Also this one.. basically you insert a number and it will do an arithmetic and tell you which number generated the longest cycle... i dont think this is too helpful but... dunno.. lol
Code:
#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;
}
Then the position of a.. c a b (but notice that c a b is already done... so you'd make a checker against all previous entries to insure there's no repition)
I'm using letters just for clarity.. but obviously same goes for numbers. The function i made is designed for numbers... (simple bubblesort algorithm)
Great idea, I'm gonna see how I can implement it. Also, to avoid repetition, don't make the 'a' decrement (it's at the beginning anyway).
I hope I'll be able to use this function the way I need to. The funny thing is, this is probably one of the easier functions that I'll have to make in one huge program that I have to do.
Hey there! Looks like you're enjoying the discussion, but you're not signed up for an account.
When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. And you can like posts and share your thoughts.
Sign Up
Bookmarks