Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the CORRECT code for this program. Im attaching the sample code with the

ID: 3806061 • Letter: I

Question

I need the CORRECT code for this program. Im attaching the sample code with the description. Thank you.

You can ignore the questions if you like.

Description: Write a C program that separates the digits of a positive integer S 10 digits long and displays the result as a table of the number of occurrences of each digit. For positive integers whose digits are all different and do not include zero, the program should determine whether or not the input is divisible by each of its individual digits and display an appropriate message. See the sample output. Your program must use 5 functions. One for separating the digits, one for displaying the table of the number of occurrences of each digit, one for checking to see if all the digits are different, one for checking to see if the input is divisible by each of its digits, and finally the main function for interacting with the user. You may assume that the user will always enter an integer. However, your program must check the input. If it is a nega tive integer, the program should prompt the user for a positive integer. Questions: When your program is complete and working correctly, use it to answer the following questions and write your answers as comments at the end of your program. (a) What is the largest integer that is divisible by all of its digits? (b) What is the second largest integer that is divisible by all of its digits? (c) How would you find the answers to the above questions by adding code using the functions in the program? Describe briefly Remember that the digits must all be different and not include zero.

Explanation / Answer

Please refer below code

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

//separating digits and adding it to array with count
void separate_digit(int num, int *digits)
{
long long int temp;
temp = num;
while(temp != 0)
{
digits[temp % 10]++;
temp = temp / 10;
}

}
//display the occuerence of each digit
void display_digits(int *digits)
{
int i;
printf("Digits: ");
for(i = 0; i <= 9; i++)
{
printf("%d ", i);
}
printf(" Occurences: ");
for(i = 0; i <= 9; i++)
{
printf("%d ", digits[i]);
}
printf(" ");
}
//checking if input number contains repeated digits
bool repeat_digits(int *digits)
{
int i;
for(i = 0; i <= 9; i++)
{
if(digits[i] >= 2)
return true;
}
return false;
}
//checking number is divisible by all its digits
bool divisible_digits(long int num,int *digits)
{
int i;
for(i = 0; i <= 9; i++)
{
if((digits[i] != 0) && (num % i))
return false;
}
return true;
}
int main()
{
long int num;
//int digits[10];

//infinite loop
while(1)
{
int digits[10] = {0};
printf(" Enter a positive integer or (zero) to end: ");
scanf("%ld", &num);
//if number is negative
if(num < 0)
{
printf(" Wrong Input ");
continue;
}
//if number is 0. We have to stop here hence break;
if(num == 0)
break;

separate_digit(num,digits);
display_digits(digits);

if(digits[0] >= 1)
printf(" Wrong Input for the second part. Input should not contain zero ");

else if(repeat_digits(digits))
{
printf(" Wrong input for the second part. Input should not contain each digit more than once. ");
}
else if(!divisible_digits(num,digits))
{
printf(" %ld is not divisible by its digits ", num);
}
else
{
printf(" %ld is divisible by its digits ", num);
}
}
return 0;
}

Please refer below output after running code

Enter a positive integer or (zero) to end: 123
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 0 1 1 1 0 0 0 0 0 0


123 is not divisible by its digits


Enter a positive integer or (zero) to end: 1000233
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 3 1 1 2 0 0 0 0 0 0


Wrong Input for the second part.
Input should not contain zero


Enter a positive integer or (zero) to end: 12223
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 0 1 3 1 0 0 0 0 0 0


Wrong input for the second part.
Input should not contain each digit more than once.


Enter a positive integer or (zero) to end: 248
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 0 0 1 0 1 0 0 0 1 0


248 is divisible by its digits


Enter a positive integer or (zero) to end: 1248
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 0 1 1 0 1 0 0 0 1 0


1248 is divisible by its digits


Enter a positive integer or (zero) to end: 9867321
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 0 1 1 1 0 0 1 1 1 1


9867321 is not divisible by its digits


Enter a positive integer or (zero) to end: 9867312
Digits: 0 1 2 3 4 5 6 7 8 9
Occurences: 0 1 1 1 0 0 1 1 1 1


9867312 is divisible by its digits


Enter a positive integer or (zero) to end: -2


Enter a positive integer or (zero) to end: 0

Process returned 0 (0x0) execution time : 89.677 s
Press any key to continue.