全文预览

C语言练习题及答案

上传者:学习一点 |  格式:docx  |  页数:186 |  大小:110KB

文档介绍
);Р    elseР    printf("%d is a prime number\n",b);Р     Р}Р参考答案:#include "stdio.h"Рint Fun(int m);Рint main()Р{                Р    int m, flag;Р Р    printf("Please input a number:\n");Р    doР    {                Р        scanf("%d", &m); //1Р    }Р    while (m < 2); //e1Р Р    flag = Fun(m); //3Р Р    if (flag) //1Р        printf("%d is a prime number\n", m);Р    elseР        printf("%d is not a prime number\n", m); //1Р Р    return 0;Р}                Рint Fun(int m)//2Р{                Р    int i, flag = 1; //1Р Р    for (i = 2; i < m; i++) //1Р    {                Р        if (m % i == 0) //1Р        {                Р            flag = 0; //1Р            break;Р        }Р    }Р    return flag;//2Р}               Р - ---------------------------------------------------------5Р6.求1898

收藏

分享

举报
下载此文档