本文目錄一覽:
用C語言求10000以內的勾股弦數怎麼求
直接輸出帶文件了,很方便
#includefstream
using namespace std;
int main(){
int a,b,c,count=0;
ofstream ofile; //定義輸出文件
ofile.open(“myfile.txt”);
ofile”勾股弦數有:”endl;
for(c=5;c=10000;c++)
for(b=4;bc;b++)
for(a=3;ab;a++){
if(c*c==b*b+a*a){
ofilec’\t’b’\t’aendl;
count++;
if(count%10==0) ofileendl;
}
}
ofile”共計:”count”個。”endl;
ofile.close(); //關閉文件
return 0;
}
C語言求勾股數,提示WA,求解?
如圖所示,f這裡清零一下就好了,上一個循環f=1之後沒有f=0的時候,就一直是1了,if里的判斷就算不成立,還會輸出i。望採納。。。。。。
c語言求勾股數
#include “stdafx.h”
int main()
{
int i;
scanf(“%d”, i);
for(int a = 1; a = i; a++)
{
for(int b = a; b = i; b++)
{
for(int c = b; c = i; c++)
{
if(a*a + b*b == c*c)
{
printf(“%d %d %d\n”, a, b, c);
}
}
}
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/289576.html