Untitled
unknown
plain_text
2 years ago
772 B
6
Indexable
#include <stdio.h>
#include <stdbool.h>
int main()
{
int number, digitToLookFor, count = 0, position = 0;
int positions[10];
scanf("%d", &number);
scanf("%d", &digitToLookFor);
bool found = false;
while (number > 1)
{
++position;
int digit = number % 10;
number = (int)number / 10;
if (digit == digitToLookFor)
{
found = true;
++count;
positions[count - 1] = position;
};
};
if (found)
{
printf("Found\n");
printf("%d times\n", count);
printf("In positions\n");
for (int i = 0; i < count; i++)
{
printf("%d ", positions[i]);
};
}
else
{
printf("Not Found");
};
};Editor is loading...