Answer the question
In order to leave comments, you need to log in
Why does the program output the same number?
Task:
Find sequences of digits in the string, consider each of them as a number in the number system that corresponds to the maximum digit, replace the numbers in the string with symbols with codes derived from these numbers. Example: aaa010101bbb343ccc - binary and five-digit number systems.
The code:
#include <stdio.h>
#include <math.h>
int funcc(char a[]) {
int length = strlen(a);
printf("length = %d\n", length);
char num[255];
int w;
int check = 0;
for (int i = 0; i < length; i++)
{
if (a[i] >= '0' && a[i] <= '9') {
num[i] = a[i];
if (i == length - 1) {
w = atoi(num);
int secondw = w;
if (check == 1) {
printf("w = %d\n", w);
int a = 0;
while (w > 0) {
int b = w % 10;
if (b > a) {
a = b;
}
w /= 10;
}
a++;
printf("sistema schisleniya = %d\n", a);
int ssm = 0;
int u = 0;
while (secondw > 0) {
ssm += secondw % 10 * pow(a, u);
secondw /= 10;
u++;
}
printf("perevod = %d\n\n", ssm);
check = 0;
}
}
check = 1;
continue;
}
else {
w = atoi(num);
int secondw = w;
if (check == 1) {
printf("w = %d\n", w);
int a = 0;
while (w > 0) {
int b = w % 10;
if (b > a) {
a = b;
}
w /= 10;
}
a++;
printf("sistema schisleniya = %d\n", a);
int ssm = 0;
int u = 0;
while (secondw > 0) {
ssm += secondw % 10 * pow(a, u);
secondw /= 10;
u++;
}
printf("perevod = %d\n\n", ssm);
check = 0;
}
continue;
}
}
}
int main()
{
char mas[19] = "010101bbbccc53534";
funcc(mas);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question