Doubt regarding conversion from int to array

how should i store a value from int to array

hi @aryaman.harshu I’d suggest you to use a string for this question. Take input for a string, then store the digit to be searched in a character. You can easliy traverse the string after that.

@aryaman.harshu please tell what problem you are facing?

@aryaman.harshu this should be while no != 0 or while no > 0
image

array must be initialized with a brace-enclosed initializer 7 | int a[100] = no;

im getting this error while storing the integer in the array

hi @aryaman.harshu can you tell me what are you trying to do with this line?
image

im trying to store the number in int as well as array so that from in i can find how many digits are there and then use it to read that same number in array so that i can use linear search

@aryaman.harshu yeah you cannot do that.
you will have to manually extract each digit of the number and store it individually in each index if you wish to do that.

so i did extract it in the array altough the number would be reversed but for this question itll work but still im getting 0 as ans

heres the code https://ide.codingblocks.com/s/305132

no the syntax you used is wrong it will not work. It will not assign inidividual digits as elements.

so how should do it and also pls send the code which is more efficient than this

ill appreciate if you give me reply today

hi @aryaman.harshu sorry for the late reply
you are trying to store the values of a number into an array, so thats what im going to discuss instead of an alternative approach
So a number 1234 should be stored like {1,2,3,4}, right?

int digits = //count no of digits in the numbers and assign it here
int arr[digits];
for (int i = digits-1; i>=0; i--) {
   arr[i] = n%10;
   n = n/10;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.