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

平均工資排序C語言

發布時間: 2023-01-05 15:53:07

① 用c語言編寫:有30個人的工資,存放在一個一維數組中,編寫程序求平均工資,最

int i; float c[30], t,a,h,l;// c是工資,t總和 a平均 h最高 l最低
av=0;h=c[0];l=c[0];t =c[0];
for(i=1;i<30;i++) {
if (c[i]>h) h=c[i];
if (c[i]<l) l=c[i];
t=t+c[i];
}
a=t/30;

② 用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就輸出最小的。這個是輸出最大的

③ c語言編一個工資管理系統 本系統能夠方便、靈活地實現職工工資的輸入、添加、刪除等編輯操作以及查詢等

*/#include "stdafx.h"
#include "iostream"
#include "string"
#include "list"
#include "cassert"
using namespace std;/*
編號、姓名、部門、應付工資、保險、稅金、實付工資。
其中實付工資由公式計算得到:實付工資=應付工資 - 保險- 稅金
*/
struct employee{
string m_num;//編號
string m_name;//姓名
string m_dep;//部門
double m_salary;//應付工資
double m_insurance;//保險
double m_tax;//稅金
};/*
(1)錄入:輸入職工數據,其中「實付工資」通過計算得到;
(2)刪除:刪除指定的職工信息(輸入姓名,若找到則刪除該信息)
(3) 修改:允許對已經錄入的數據重新進行編輯、修改;
(4) 顯示:顯示全體職工數據;
(5)查詢:
a. 輸入職工姓名,顯示該職工的全部數據;
b. 輸入某部門值,顯示該部門職工的數據、工資總額、平均工資。
(6) 退出程序。
*/list<employee> emps;int _tmain(int argc, _TCHAR* argv[])
{
void print(const employee &e);
void input();
void del();
void mod();
void show_all();
void show_name();
void show_dep();cout<<"簡易職工薪水管理程序 by 做他\n";// delete this line
cout<<"版權沒有 請隨意復制或修改任何代碼\n";//delete this linecout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
int choose=0;
cin>>choose;
assert(!cin.fail());
while (choose!=6)
{
if (choose==1) input();
if (choose==2) del();
if (choose==3) mod();
if (choose==4)
{
int choice=0;
cout<<"請選擇操作 1.按姓名查詢 2.按部門查詢 3.退出:";
cin>>choice;
if (choice==1) show_name();
if (choice==2) show_dep();
if (choice==3)
{
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
cin>>choose;
assert(!cin.fail());
continue;
}
}
if (choose==5) show_all();
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
cin>>choose;
assert(!cin.fail());
}
return 0;
}void print(const employee &e)
{
cout<<"編號:"<<e.m_num<<endl;
cout<<"姓名:"<<e.m_name<<endl;
cout<<"部門:"<<e.m_dep<<endl;
cout<<"保險:"<<e.m_insurance<<endl;
cout<<"稅金:"<<e.m_tax<<endl;
cout<<"應付工資:"<<e.m_salary<<endl;
cout<<"實付工資:"<<e.m_salary-e.m_insurance-e.m_tax<<endl;
}void input()
{
string num,name,dep;
double salary,ins,tax;
cout<<"請輸入員工編號:";
cin>>num;
cout<<"請輸入員工姓名:";
cin>>name;
cout<<"請輸入員工部門:";
cin>>dep;
cout<<"請輸入員工保險:";
cin>>ins;
assert(!cin.fail());
cout<<"請輸入員工稅金:";
cin>>tax;
assert(!cin.fail());
cout<<"請輸入員工應付工資:";
cin>>salary;
assert(!cin.fail());
employee temp;
temp.m_dep=dep;
temp.m_insurance=ins;
temp.m_name=name;
temp.m_num=num;
temp.m_salary=salary;
temp.m_tax=tax;
emps.push_back(temp);
cout<<"員工錄入操作完畢.\n";
}void del()
{
if (emps.size()==0)
{
cout<<"沒有員工記錄.\n";
return;
}
string name;
bool isfind=false;
cout<<"請輸入要刪除的員工姓名:";
cin>>name;
list<employee>::iterator iter;
for (iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
emps.erase(iter);
cout<<"姓名為\""<<name<<"\"的員工記錄已刪除.\n";
return;
}
}
if (!isfind)
{
cout<<"沒有找到姓名為\""<<name<<"\"的員工.\n";
return;
}
}void mod()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
bool isfind=false;
string name;
cout<<"請輸入要修改的員工姓名:";
cin>>name;
list<employee>::iterator iter;
for (iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
cout<<"姓名為\""<<name<<"\"的員工記錄已找到.\n";
break;
}
}
if (isfind)
{
string num,name,dep;
double tax,ins,salary;
print(*iter);
cout<<endl;
cout<<"請輸入新的員工編號:";
cin>>num;
cout<<"請輸入新的員工姓名:";
cin>>name;
cout<<"請輸入新的員工部門:";
cin>>dep;
cout<<"請輸入新的員工保險:";
cin>>ins;
assert(!cin.fail());
cout<<"請輸入新的員工稅金:";
cin>>tax;
assert(!cin.fail());
cout<<"請輸入新的員工工資:";
cin>>salary;
assert(!cin.fail());
iter->m_dep=dep;
iter->m_insurance=ins;
iter->m_name=name;
iter->m_num=num;
iter->m_salary=salary;
iter->m_tax=tax;
cout<<"1 員工記錄被成功修改.\n";
}
else
{
cout<<"沒有找到姓名為\""<<name<<"\"的員工記錄.\n";
}
}void show_all()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
cout<<"顯示全體員工數據:\n";
cout<<"--------------------\n";
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
cout<<endl;
print(*iter);
cout<<endl;
}
cout<<"--------------------\n";
}void show_name()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
bool isfind=false;
string name;
cout<<"請輸入要查詢的員工姓名:";
cin>>name;
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
cout<<"姓名為\""<<name<<"\"的員工記錄已找到.\n";
print(*iter);
break;
}
}
if (!isfind)
{
cout<<"沒有找到姓名為\""<<name<<"\"的員工.\n";
return;
}
}void show_dep()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
double isfind=0.00;
double total_salary=0.00;
string dep;
cout<<"請輸入要查詢的部門名稱:";
cin>>dep;
cout<<"部門["<<dep<<"]的員工信息:\n";
cout<<"--------------------\n\n";
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_dep==dep)
{
isfind++;
total_salary+=iter->m_salary;
print(*iter);
cout<<endl;
continue;
}
}
cout<<"--------------------\n";
if (isfind==0)
{
cout<<"沒有找到名稱為["<<dep<<"]的部門.\n";
}
else
{
cout<<"部門["<<dep<<"]工資統計:\n";
cout<<"工資總額:"<<total_salary<<endl;
cout<<"平均工資:"<<total_salary/isfind<<endl;
}
}

④ C語言程序設計 輸入10名職工的職工號和工資,計算平均工資並輸出低於平均工資的職工號和工資。

我給你編寫了一個簡單的,你自己參考一下,自己潤色吧!!!
#include<stdio.h>
typedef struct employee
{
char employee_num[15];
float salary;
}employee;
main()
{
employee A[10];
for(int i=0;i<10;i++)
{
printf("input the number and the salary of the employee %d ",i+1);
scanf("%s %f",&A[i].employee_num,&A[i].salary);
}
float average_salary=0;
for(i=0;i<10;i++)
average_salary+=A[i].salary;
average_salary=average_salary/10;
for(i=0;i<10;i++)
{
if(A[i].salary<average_salary)
printf("%s,%.4f\n",A[i].employee_num,A[i].salary);
}
return 0;
}

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

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

⑥ 設計一個公司的數據結構,並使用結構指針數組儲存職員信息,統計公司員工工資總額和平均工資。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; }

⑦ 用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);

}

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

⑧ 用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 個人的平均工資 */

}