Easy Tutorial
❮ C Function Strrchr C Bit Fields ❯

C Exercise Example 85

C Language Classic 100 Examples

Title: Determine how many 9s a prime number can divide.

Program Analysis: Damn! This question means to determine how many 9s a prime number can divide, right? I'll just understand it this way. A prime number cannot be divided by any number other than 1 and itself.

Program Source Code:

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015 tutorialpro.org. All rights reserved.
//

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int p,i;
    long int sum=9;
    printf("Please enter a prime number:\n");
    scanf("%d",&p);
    for(i=1;;i++)
        if(sum%p==0)break;
        else sum=sum*10+9;

    printf("The prime number %d can divide %d 9s to form the number %ld\n",p,i,sum);
    return 0;
}

The above example outputs the following result when run:

Please enter a prime number:
13
The prime number 13 can divide 6 9s to form the number 999999

C Language Classic 100 Examples

❮ C Function Strrchr C Bit Fields ❯