generate functionThu, 22 Jun 2023

you have to calculate the number of appearences of a digit in a range of numbers. you have to create a function named "calculate_digit" which receives this parameters: initiation: the number that starts the range final: the number that ends the range digit: the digit requested by the user the function has to return the amount of appearences of the digit that the user said. you cant use for, only while

int calculate_digit(int initial, int final, int digit) { int cont = 0; while (initial<=final) { int temp = initial; while (temp>0) { if (temp%10==digit) { cont++; } temp = temp/10; } initial++; } return cont; }

Questions about programming?Chat with your personal AI assistant