當前位置:首頁 » 編程語言 » 數值統計c語言1045
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

數值統計c語言1045

發布時間: 2022-05-17 06:36:44

c語言 for 循環 數據統計問題:從鍵盤輸入一批任意數量的整數,統計其中不大於100的非負數數值的個數。

你的程序不管是不是負數a都會增加
continue;是執行下一次循環但是同時a也增加了並不會因為coninue而沒增加
只需在判斷b是否會負數的地方a--就可以達到要的效果,代碼如下:
#include <stdio.h>
void main()
{
long int a, b;

for(a=0; b!=0; a++)
{
printf("please input interal numbers and input 0 to stop:");

scanf("%ld", &b);

if (b<0)
{
a--;
continue;
}

printf("\n");
}

printf("suitable number: %d\n", a-1);
}

② 用c語言統計數字出現的次數

b[a[i]]++; a[i] 是數組元素,數值在0-9范圍內,所以b[a[i]] 總在 b[0]到b[9]之間。
b[] 已初始化為 0。
b[a[i]]++; 是 b[a[i]]=b[a[i]]+1; 它是累加器。
可以看成: x=a[i]; b[x]=b[x]+1; 第一次 b[x]++變1,第二次 b[x]++變2, 第三次 b[x]++變3。 例如 i=1,7,9 時 x=5,b[5] 累加3次變3。 這樣就統計出5出現的次數了。

③ 數值統計 C語言!!!

#include<stdio.h>
intmain()
{intn,z,f,l;floatx;
scanf("%d",&n);
while(n>0)
{for(z=f=l=0;n--;)
{scanf("%f",&x);
if(x>0)z++;
elseif(x<0)f++;
elsel++;
}
printf("%d%d%d ",f,l,z);
scanf("%d",&n);
}
return0;
}