让一切随风 Admin
帖子数 : 257 注册日期 : 12-11-03 年龄 : 32 地点 : 湖南
| 主题: 检查一个数是否为质数 周六 四月 20, 2013 8:53 pm | |
| 【检查一个数是否为质数】Time Limit:1000MS Memory Limit:10000KTotal Submit:2938 Accepted:948 Description 输入一个正整数,检查该数是否为质数Input 输入一个正整数Output 输出Y或者NSample Input 输入34Sample Output NHint 质数即素数 - 代码:
-
[font='Times New Roman']#include <stdio.h>[/font]
[font='Times New Roman']int main()[/font]
[font='Times New Roman']{[/font]
[font='Times New Roman'] int a,i;[/font]
[font='Times New Roman'] scanf("%d",&a);[/font]
[font='Times New Roman'] for(i=2;i<a;i++){[/font]
[font='Times New Roman'] if(a%i==0){[/font]
[font='Times New Roman'] break;[/font]
[font='Times New Roman']}[/font]
[font='Times New Roman'] }[/font]
[font='Times New Roman'] if(i<a){[/font]
[font='Times New Roman'] printf("N\n");[/font]
[font='Times New Roman'] }[/font]
[font='Times New Roman'] else{[/font]
[font='Times New Roman'] printf("Y\n");[/font]
[font='Times New Roman'] }[/font]
[font='Times New Roman'] return 0;[/font]
[font='Times New Roman']}[/font]
| |
|