# C programing code

#### narendra225

this program is based on the binary unit base which I created in 2005 in college time by using only if function and loop function even I ask for chatgpt and google bard but code is not working can anyone help me to creating this code

#### narendra225

i write code c code but here use array
#include <stdio.h>

int main() {
printf("Dear friend, I will guess your number using the binary system.\n");
int guess = 0;

// Arrays to hold the numbers for each iteration
int numbers[5][16] = {
{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31},
{2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31},
{4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31},
{8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31},
{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
};

// Loop for each iteration
for (int i = 0; i < 5; i++) {
printf("Is your number in the following list?\n");
for (int j = 0; j < 16; j++) {
printf("%d ", numbers[j]);
}
printf("\nEnter '1' if yes, '0' if no: ");

guess += numbers[0];
}
}

return 0;
}

i want number generated by loop not by array

#### FResher

very good and funny !

use all formulas you use to build your array and each series number.
create the base formula you build as function, you'll get 5 new function.

A : start : 1 ,then n+2 until 16 members
B : start : 2 ,then every duets are b = a + 1, then 3 is added at the 2nd number.
C : start : 4 ,then for the 3 after it's +1 apply, then to change the group, add 5 to last of the quadret.
D : start : 8 ,n+1 until 8 numbers are in the group. then n+9
E : start : 16 ,then n+1 apply until 31

the head of all arrays are pow(2) members, and assume being part of the final 'guess'.

#### WhiteCube

Way too complicated FResher.

Only one simple function is needed.

F(a,b): examine integer a, return true if bit b is set

Keep the i loop as it is.

Change the j loop, from 0 to 31.

Print j if F(j,i)

#### narendra225

can you create C code without 2d array only on logic

#### FResher

Way too complicated FResher.

Only one simple function is needed.

F(a,b): examine integer a, return true if bit b is set

Keep the i loop as it is.

Change the j loop, from 0 to 31.

Print j if F(j,i)
I was just making the details about current n-dimension arrays in the original code.
Hoping a ( without defined Array ) generator/methods for build all values.

It's a description about "how" was made all rows in the array.

Look closer at each array, you 'll see the logical in.
It's big arrays with sub-groups inside, except the first and the last.

details , that all values to build to achieve without arrays :
C:
``````{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31} n+2

-------------------------------------------------------------
{2, 3 | 6, 7 | 10, 11 | 14, 15 | 18, 19 | 22, 23 | 26, 27 | 30, 31} 8 sub groups n+1,gap n+1+3
-------------------------------------------------------------
{4, 5, 6, 7 | 12, 13, 14, 15 | 20, 21, 22, 23 | 28, 29, 30, 31 } 4 sub groups n+1, gap n+5
-------------------------------------------------------------
{8, 9, 10, 11, 12, 13, 14, 15 | 24, 25, 26, 27, 28, 29, 30, 31 } 2 sub groups n+1, gap 9
-------------------------------------------------------------
{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31} n+1``````

Last edited:

#### narendra225

#include <stdio.h>

void printNumbers(int start, int increment, int end) {
while (start <= end) {
for (int i = start; i < start + increment && i <= end; i++) {
printf("%4d ", i);
}
printf("\n");
start += increment * 2;
}
}

int main() {
int number;
printf("Enter a number (1, 2, 4, 8, 16,32,64,128,256): ");
scanf("%d", &number);

int start = number;
int end = 511;

switch (number) {
case 1:
printNumbers(start, 1, end);
break;
case 2:
printNumbers(start, 2, end);
break;
case 4:
printNumbers(start, 4, end);
break;
case 8:
printNumbers(start, 8, end);
break;
case 16:
printNumbers(start, 16, end);
break;
case 32:
printNumbers(start, 32, end);
break;
case 64:
printNumbers(start, 64, end);
break;
case 128:
printNumbers(start, 128, end);
break;

case 256:
printNumbers(start, 256, end);
break;
default:

printf("Invalid number entered.\n");
break;
}

return 0;
}

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

### Members online

No members online now.