c语言求整数均值
A. 濡备綍鐢╟璇瑷杈揿叆5涓鏁存暟锛屾眰鍜岋纴姹傚钩鍧囧硷纻
涓嬮溃鏄涓涓狢璇瑷绋嫔簭镄勪緥瀛愶纴瀹冭兘澶熷疄鐜拌緭鍏ヤ簲涓鏁存暟锛岃$畻鍏朵腑姝f暣鏁扮殑绱锷犲拰sum浠ュ强姝f暣鏁扮殑骞冲潎鍊糰ve锛屽苟杈揿嚭缁撴灉銆
绋嫔簭涓锛屾垜浠浣跨敤浜嗕竴涓猣or寰鐜锛屽惊鐜浜旀℃潵璇诲彇杈揿叆镄勪簲涓鏁存暟x銆傚傛灉璇诲叆镄刹鏄姝f暣鏁帮纴鍒椤皢瀹幂疮锷犲埌sum涓锛屽苟涓旇℃暟鍣╟ount锷1銆傛渶钖庯纴鎴戜滑璁$畻姝f暣鏁扮殑骞冲潎鍊糰ve锛屽苟浣跨敤printf鍑芥暟杈揿嚭缁撴灉銆傚叾涓锛%.2f鐢ㄦ潵杈揿嚭涓涓灏忔暟镣瑰悗淇濈暀涓や綅镄勫疄鏁般
涓嬮溃鏄涓缁勮緭鍏ヨ緭鍑虹殑渚嫔瓙锛屼互灞旷ず绋嫔簭镄勮繍琛屾晥鏋滐细
杈揿叆锛-3 0 2 5 -1
杈揿嚭锛歴um=7
ave=3.50
鍦ㄤ笂闱㈢殑渚嫔瓙涓锛岃緭鍏ヤ简浜斾釜鏁存暟-3銆0銆2銆5鍜-1銆傚叾涓锛屾f暣鏁版湁涓や釜锛屽垎鍒鏄2鍜5锛屽畠浠镄勭疮锷犲拰鏄7锛屽钩鍧囧兼槸3.50銆傜▼搴忔g‘鍦拌緭鍑轰简杩欎袱涓缁撴灉銆
B. c语言计算两个整数的平均值
#include<stdio.h>
int main()
{
int a,b;
double result;
scanf("a = %d , b = %d ",&a,&b);
result = (double)(a+b)/2;
printf("两个整数的平均值 result = % lf\n", result);
return 0;
}
C. C璇瑷杈揿叆涓変釜鏁存暟,璁$畻骞惰緭鍑哄畠浠镄勫钩鍧囧
int main(void)鍙浠ヤ慨鏀规垚void main銆俫etchar()鏄涓轰简绋嫔簭涓岖珛鍒昏繑锲烇纴鑳藉熺湅鍒板睆骞曡緭鍑虹殑鏁版嵁锛屼篃鍙浠ヤ笉浣跨敤銆
杈揿叆涓変釜鏁存暟璁$畻骞惰緭鍑哄畠浠镄勫钩鍧囧肩殑婧愪唬镰佸备笅锛
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<(a+b+c)/3;
return 0;
}
镓╁𪾢璧勬枡
姹傛暣鏁扮殑鍜屼笌鍧囧肩殑婧愪唬镰佸备笅锛
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,a;
cin>>n;
long long sum=0;
double pjz;
for(long long i=1;i<=n;i++)
{
cin>>a;
sum+=a;
}
pjz=sum/(double)n;
printf("%lld %.5lf",sum,pjz);
return 0;
}