1
我需要编写一个程序,计算3^2 + 6^2 + 9^2 + ... +(3×N)^ 2,给定一个给定整数N的用户。程序会提示用户输入一个整数,是小于20.该方案应经过3个错误chances.This站是我的代码:我的程序忽略'while'循环
#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循环。请帮忙。