Write a C program for recursive function named sum digits() for computing sum of digits of a positive integer (up to six digits long). Read a list of positive integers in an array and print the number(s) which has (have) the maximal sum of digits. a Run your program for the following input data set and provide the results with input datasets in a separate output file. (i) 35, 467, 1234, 89, 145, 912, 0, 1000, 10000 (ii) 856, 1000, 94, 19, 205, 489, 75, 57.
Answers
Answered by
0
Answer:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
int sum(int n)
{
int sum = 0;
while(n != 0)
{
int last = n%10;
sum = sum + last;
n /= 10;
}
return sum;
}
void main()
{
srand(time(NULL));
int ran = rand() % 10000;
printf("The sum of digits of %d is %d" , ran , sum(ran));
getch();
}
Explanation:
Similar questions