【发布时间】:2015-11-23 02:05:57
【问题描述】:
我需要编写一个程序,计算 3^2+6^2+9^2+ ... +(3×N)^2,对于给定整数 N 的用户。程序提示用户输入小于 20 的整数。程序应在 3 次错误机会后停止。这是我的代码:
#include <stdio.h>
int main(){
int n,x,i ;
float p;
printf("Hey give me a positive integer number smaller than 20 \n ");
scanf("%d" ,&n);
x=3;
p=0;
while ((n<=0) && (n>=20)){
printf("wrong input %d chances left \n" ,x);
x--;
if (x==0) return 0;
scanf("%d" , &n);
}
for ( i=0; i<=n; i++){
p= (3*i)* (3*i) + p ;
}
printf("Yeah.. thats the result bro %f \n" , p);
return 0;
}
我不知道为什么它不会进入 while 循环。请帮忙。
【问题讨论】:
标签: c