December 8, 2023 # Belajar Bahasa C – Persistent Bugger

Write a function, `persistence`, that takes in a positive parameter `num` and returns its multiplicative persistence, which is the number of times you must multiply the digits in `num` until you reach a single digit.

For example (Input –> Output):

``````39 --> 3 (because 3*9 = 27, 2*7 = 14, 1*4 = 4 and 4 has only one digit)
999 --> 4 (because 9*9*9 = 729, 7*2*9 = 126, 1*2*6 = 12, and finally 1*2 = 2)
4 --> 0 (because 4 is already a one-digit number)``````

Solution:

``````int persistence(int n)
{
int x = 0;
while (n > 9)
{
int m = 1;
while (n)
{
m = m * (n % 10);
n = n / 10;
}
n = m;
x++;
}
return x;
}`````` #### Rajo Intan

Blogger, pemiliki Onestring Lab, menulis artikel terkait teknologi informasi dan pendidikan. Web Developer, berpengalaman lebih dari 20 tahun mengembangkan berbagai aplikasi dan sistem informasi. Kerjasama kontak di onestringlab@gmail.com atau https://forms.gle/xAGKkpi6B3BzJyzk7

View all posts by Rajo Intan →
{"ft_lang_label":"__label__en","ft_lang_prob":0.7548743,"math_prob":0.9703594,"size":610,"snap":"2023-40-2023-50","text_gpt3_token_len":217,"char_repetition_ratio":0.11056106,"word_repetition_ratio":0.0,"special_character_ratio":0.43114755,"punctuation_ratio":0.13669065,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99486876,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,2,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-08T13:03:36Z\",\"WARC-Record-ID\":\"<urn:uuid:a9de6ae1-1975-47e4-b7f7-9b1c98997eb8>\",\"Content-Length\":\"107090\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:23137394-53fe-4337-b221-17e8fc8bc0ba>\",\"WARC-Concurrent-To\":\"<urn:uuid:4a33a397-4781-4b50-82a7-8a1492cfa581>\",\"WARC-IP-Address\":\"159.89.202.113\",\"WARC-Target-URI\":\"https://onestringlab.com/persistent-bugger/\",\"WARC-Payload-Digest\":\"sha1:2ESSW47KR3QQLQFA7OZOVWW66MXSJOKI\",\"WARC-Block-Digest\":\"sha1:T75MB5MEALWLJ6CTAZH7DCZUTXOHCSCQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100745.32_warc_CC-MAIN-20231208112926-20231208142926-00651.warc.gz\"}"}