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

c語言統計平均工資

發布時間: 2022-07-28 05:34:52

A. 設計一個公司的數據結構,並使用結構指針數組儲存職員信息,統計公司員工工資總額和平均工資。c語言

/* please input the total number of employees : 3 please input 1/3 massage:name age salary 胥立暢 32 6890.50 please input 2/3 massage:name age salary 王瑩瑩 24 3698.85 please input 3/3 massage:name age salary 李大海 28 4896.80 胥立暢 32 6890.00 王瑩瑩 24 3698.00 李大海 28 4896.00 Press any key to continue */ #include <stdio.h> #include <string.h> #include <malloc.h> typedef struct employee { int age; char *name; double salary; }PEMP; void update(PEMP a[],int id,int age,char *name,double salary) { a[id].age = age; a[id].salary = salary; a[id].name = (char *)malloc(strlen(name)*sizeof(char) + 1); strcpy(a[id].name,name); } void reading(PEMP a[],int n) { int i,age; double salary; char name[30]; for(i = 0;i < n;++i) { printf("please input %d/%d massage:name age salary\n",i + 1,n); scanf("%s %d %lf",name,&age,&salary); update(a,i,age,name,salary); } } double Adp(PEMP *a,int n) { int i; double sum = 0.0; for(i = 0; i < n; ++i) sum += a[i].salary; return sum; } void Show(PEMP a[],int n) { int i; for(i = 0; i < n; ++i) printf("%s %d %.2lf\n",a[i].name,a[i].age,a[i].salary); printf("\n"); } int main() { int n; double sum; PEMP company[30]; printf("please input the total number of employees : "); scanf("%d",&n); reading(company,n); Show(company,n); sum = Adp(company,n); printf("工資總額:%.2lf,平均工資 : %.2lf\n",sum,sum/n); return 0; }

B. c語言作業

//注意輸入的時候不能輸入空數(直接按enter),否則計算的平均工資將出錯
#include
void main()
{
double money_ave[4];
int money,n,i;
for (n=1;n<4;n++)
{ printf("請依次輸入第%d個班組各成員的工資(元) ",n);
i=0;
money=0;
while (1)
{
i++;
scanf("%d",&money);
if (money==-1)
{
i--;
break;
}
money_ave[n]+=money;
}
money_ave[n]=( float )money_ave[n]/( float )i;
}
for (n=1;n<4;n++)
printf("第%d個班組的平均工資為%f(元) ",n,money_ave[n]);
}

C. c語言編程:建立一個結構體數組

分析題意:

一、要定義兩個結構體,一個是日期年月日,一個是員工。

二、程序包含三個功能:1、結構數組的輸入。2、結構數組的輸出。3、統計平均工資。根據編程習慣,三功能要寫成獨立函數,方便擴展和調用。

ps:員工數量定義成常量,也為編程習慣,便於修改。另外,日期驗證我只寫了月份檢測給你參考。需擴展,自行編寫函數驗證。

#include <stdio.h>

#define M 3//最大員工數量

typedef struct date

{

int year;

int month;

int day;

}YMD;

typedef struct employee

{

int id;//工號

char name[20];//姓名

YMD date;//日期

int wage;

}EME;

void inputInfo(EME emes[]);//輸入

void outputInfo(EME emes[]);//輸出

float getAvg(EME emes[]);//求平均工資

int main()

{

EME emes[M];//員工結構體數組

inputInfo(emes);

outputInfo(emes);

printf("平均工資:%f",getAvg(emes));

return 0;

}

void inputInfo(EME emes[])

{

int i;

for(i=0;i<M;i++)

{

printf("請輸入員工%d的信息: ",i+1);

printf("工號:"),scanf("%d",&emes[i].id);

printf("姓名:"),scanf("%s",emes[i].name);

printf("日期(分別輸入年月日,空格分割):"),scanf("%d%d%d",&emes[i].date.year,&emes[i].date.month,&emes[i].date.day);

if(emes[i].date.month>12 || emes[i].date.month<=0)//日期輸入的驗證不通過時,重新輸入,驗證可單獨寫函數,這里只做參考!

{

printf("輸入日期不符合,請重新輸入! "),i--;

continue;

}

printf("工資:"),scanf("%d",&emes[i].wage);

printf(" ");

}

}

void outputInfo(EME emes[])

{

int i;

printf("所有員工的信息為:---------------------------- ");

for(i=0,printf("員工%d的信息: ",i+1);i<M;i++)

{

printf("工號:%d ",emes[i].id);

printf("姓名:%s ",emes[i].name);

printf("日期:%04d-%02d-%02d ",emes[i].date.year,emes[i].date.month,emes[i].date.day);

printf("工資:%d ",emes[i].wage);

printf(" ");

}

}

float getAvg(EME emes[])

{

int i;

float sum=0;

for(i=0;i<M;i++)

sum+=emes[i].wage;

return sum/M;

}

D. c語言函數名:avgSalary * 功能:計算多個職工的平均工資、最高工資和最低工資 *

判斷語句出錯 應該拿上一次的high出來對比。你的判斷漏洞在於如果k大於i。i小於m的時候不成立

E. 用C語言編寫一個求10個人平均工資的程序

#include<stdio.h>
void main()
{
float wages[10],sum=0;
int i;
printf("請輸入10人工資\n");
for(i=0;i<10;i++){
scanf("%f",&wages[i]);
sum=sum+wages[i];
}
printf("平均工資為%7.2f\n",sum/10);

}

純手工~可能會有小錯誤,思路應該沒有問題。

F. 統計全單位人員的平均工資。單位的人數不固定,工資數從鍵盤先後輸入

用IF循環語句,可以設置一個輸入結束的字元如Q進行判斷是否結束輸入,通過循環錄入員工工資,並將輸入的工資數每次加到總數里,輸入次數也計算下,最後出平均結果,篩選也可以用循環判斷下符合條件的列印出來

G. 用c語言編寫一個求n個人平均工資的程序

#include
<stdio.h>
void
main(
)
{
int
n
=
0
,
i
=
0
;
float
total_salary
=
0.0,
every_salary
=
0.0
;
scanf("%d",
&n)
;
/*
輸入要計算的
n
個人
*/
for(
i
=
1
;
i
<=
n
;
i
++
)
{
scanf("%f",
&every_salary)
;
/*
輸入每一個人的薪水
*/
total_salary
+=
every_salary
;
/*
全部薪水變數進行累加
*/
}
printf("Average
salary
is:
%f\n",
total_salary/n)
;
/*
循環結束後輸出
n
個人的平均工資
*/
}

H. 用C語言寫一個程序,要求如下:用C語言表示10個人在3個月中平均工資的程序

#include<stdio.h>
#define NUM 3
struct pep
{
float one;
float two;
float three;
}PP[NUM];
int max(struct pep *x,struct pep *y)
{
if((x->three/x->one)>(y->three/y->one))return -1;
else if((x->three/x->one)<(y->three/y->one))return 1;
else
return 0;
}
int main()
{ int i;
for(i=0;i<NUM;i++)
{
scanf("%f %f %f",&PP[i].one,&PP[i].two,&PP[i].three);
}
qsort(PP,NUM,sizeof(struct pep),max);
printf("%.2f %.2f %.2f ",PP[0].one,PP[0].two,PP[0].three);

printf("\n");

}
要三十行就把輸入語句拆成三個,max函數裡面-1變1,1變-1就輸出最小的。這個是輸出最大的

I. 請大神幫忙用循環結構設計下面這個程序。。C語言。

float s; //每個人工資
float t=0; //工資總和
int n=0; //人數
scanf("%f", &s);
if(s != -1)
{ do
{t = t+s;
n++;
scanf("%f", &s);
}while(s!= -1);
printf("%f", t/n);
}

J. c語言編程:計算四項工資平均值,並將結果保存到新文件中 我目前寫的如下,幫忙改

你沒寫保存文件的代碼