天涯人论坛
先登录吧!!!
登录可以体验更多权限哦!!!
天涯人论坛
先登录吧!!!
登录可以体验更多权限哦!!!
天涯人论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.
天涯人论坛

为编程爱好者打造一个学习、交流的平台。
 
首页首页  欢迎页欢迎页  Latest imagesLatest images  注册注册  登录登录  
论坛刚刚起步,欢迎大家多多支持! 如果有想申请管理员或版主的请给管理员留言!!!
欢迎大家积极发帖!

 

 检查一个数是否为质数

向下 
作者留言
让一切随风
Admin
让一切随风


帖子数 : 257
注册日期 : 12-11-03
年龄 : 32
地点 : 湖南

检查一个数是否为质数 Empty
帖子主题: 检查一个数是否为质数   检查一个数是否为质数 Empty周六 四月 20, 2013 8:53 pm

【检查一个数是否为质数】



Time Limit:1000MS Memory Limit:10000K

Total Submit:2938 Accepted:948



Description



输入一个正整数,检查该数是否为质数



Input



输入一个正整数



Output



输出Y或者N



Sample Input





输入34



Sample Output





N



Hint



质数即素数



代码:



[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]



返回页首 向下
http://tyren.longluntan.org
 
检查一个数是否为质数
返回页首 
1页/共1

您在这个论坛的权限:不能在这个论坛回复主题
天涯人论坛 :: 我爱编程 :: c语言-
转跳到: