Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C solution to codeabbey challenge 24
- #include <stdio.h>
- int isInVec(int arr[], int val, int size){
- for (int j = 1; j < size; j++){
- if (arr[j] == val){
- return 1;
- }
- }
- return 0;
- }
- int main(){
- int seed[12] = {3488, 373, 5368, 751, 8342, 3416, 843, 6173, 7019, 381, 1054, 6303};
- int counter = 1;
- int aux = 0;
- int aux2 = 0;
- int rsp[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- int vals[115];
- for (int i = 0; i < 12; i++){
- aux = seed[i];
- while (1==1){
- aux2 = (aux*aux / 100) % 10000;
- if (isInVec(vals, aux2, counter) == 1){
- rsp[i] = counter;
- break;
- }
- vals[counter] = aux;
- counter += 1;
- aux = aux2;
- }
- counter = 1;
- }
- for (int l = 0; l < sizeof(rsp)/sizeof(rsp[0]); l++){
- printf("%d ", rsp[l]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement