C 练习实例85

C语言教程评论

C 练习实例85

题目:判断一个素数能被几个9整除。

程序分析:丫的!这题目的意思是判断一个素数能整除几个9组成的数吧?我就这么理解吧。素数是不 能被除1和自身之外的数整除的文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili85.html

实例

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int p,i;
    long int sum=9;
    printf("请输入一个素数:\n");
    scanf("%d",&p);
    for(i=1;;i++)
        if(sum%p==0)break;
        else sum=sum*10+9;

    printf("素数%d能整除%d个9组成的数%ld\n",p,i,sum);
    return 0;
}

以上实例运行输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili85.html

请输入一个素数:
13
素数13能整除6个9组成的数999999
文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili85.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili85.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月6日21:17:42
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-lianxishili85.html

发表评论