求助,急急急

编写C语言程序:

给定一个rSquare,表示一个圆的半径的平方。某元的圆心在坐标系原点,计算返回处在该圆圆周上的格点

慕先生9572614
浏览 3932回答 2
2回答

慕粉2350305356

#include<stdio.h>#include<math.h>int main(){ float rSquare; int x,y,temp,res,count = 0; scanf("%f",&rSquare); x=(int)sqrt(rSquare); y=(int)sqrt(rSquare); for(int i=0;i<=x;i++) { for (int j = 0; j <=y; j++)  { if(i*i+j*j==rSquare) count++; } } if(sqrt(rSquare)==(long)sqrt(rSquare)) { temp = count-2; res =temp*4+4; printf("%d",res); } else  { res = count*4; printf("%d",res); } return 0;}/* 又一个被开发者猩球残害的新同事 */

朱利尔1124

Java版本:public static int countPoints(int rSquare) {         if(rSquare<=2000000000&&rSquare>=1) {             int x,y,temp,res,count = 0;             x=(int)Math.sqrt(rSquare);             y=(int)Math.sqrt(rSquare);             for(int i=0;i<=x;i++){                 for (int j = 0; j <=y; j++){                     if(i*i+j*j==rSquare) {                         count++;                     }                 }             }             if(Math.sqrt(rSquare)==(long)Math.sqrt(rSquare)){                 temp = count-2;                 res =temp*4+4;                 System.out.println("格点数为" + res);                 return res;             }else{                 res = count*4;                 System.out.println("格点数为" + res);                 return res;             }         }else {             System.out.println("请输入1~2000000000之间的数");             return -1;         }     }
打开App,查看更多内容
随时随地看视频慕课网APP