哪位高人能找出我的C++程序错在哪里?小弟不胜感激

[复制链接]
查看11 | 回复2 | 2006-11-29 20:53:46 | 显示全部楼层 |阅读模式
改好了#include #includeusing namespace std; int main(){ int n,i;//n是输入的数 i是计数器 int o;//o的算术平方根 bool is_prime=true; cout > n; o=sqrt(n); i=2; while(i<=o){ if(o%i==0){ is_prime=false; break; } i++; } if(is_prime){ cout << n << "为质数"; } else{ cout << n << "为非质数"; } return 0; }
回复

使用道具 举报

千问 | 2006-11-29 20:53:46 | 显示全部楼层
同意楼上的意见错误出在:%号左面和右面的数值类型必须是整数型的所以只将O声明成整形数即可。
回复

使用道具 举报

千问 | 2006-11-29 20:53:46 | 显示全部楼层
你要输入质数,才可以输出质数,比如质数17,你输进去就可以显示为质数.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行