求C语言程序大神!
发布网友
发布时间:2023-05-10 02:46
我来回答
共2个回答
热心网友
时间:2023-06-21 20:06
#include <stdio.h>
#define N 1000 //预定义员工个数
/*定义员工结构体*/
struct Employee
{
char ID[20];
char Name[20];
float Mark1;
};
/*声明员工数组及员工数量*/
struct Employee Employees[N];
int num=0;
/*插入员工信息*/
int Employee_Insert(){
while(1){
printf("请输入员工ID:");
scanf("%s",&Employees[num].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&Employees[num].Name);
getchar();
printf("请输入业绩:");
scanf("%f",&Employees[num].Mark1);
getchar();
num++;
printf("是否继续?(y/n)");
if (getchar()=='n'){
break;
}
}
return num;
}
/*按业绩排序*/
void Employee_Sort(){
int i,j;
struct Employee tmp;
for (i=0;i<num;i++){
for (j=1;j<num-i;j++){
if (Employees[j-1].Mark1<Employees[j].Mark1){ //降序
tmp=Employees[j-1];
Employees[j-1]=Employees[j];
Employees[j]=tmp;
}
}
}
}
/*显示员工信息*/
void Employee_Display() {
int i,t;
printf("%10s%10s%20s\n","工号","姓名","业绩"); //显示格式可自行调整
printf("---------------------------------------------------------\n");
if(num>10)//员工不超过10人,全部显示
//超过10人,显示排序前10
t=10;
else
t=num;
for(i=0;i<t;++i){ //显示格式可自行调整
printf("%10s%10s%18.2f\n",
Employees[i].ID,Employees[i].Name,Employees[i].Mark1);
}
}
/*主程序*/
int main(){
Employee_Insert(); //输入员工信息
Employee_Sort(); //排序
Employee_Display();
return 0;
}
热心网友
时间:2023-06-21 20:06
1.
#include "stdio.h"
#include "string.h"
#include "math.h"
int main()
{
char a[20]={0};
int i,len;
int out=1;
printf("please input a integer str:");
gets(a);
len=strlen(a);
for(i=0;i<len;i++)
out+=(a[i]-'0')*pow(10.0,len-1-i);
printf("该整数字符串转成整数再加上1后值为%d\n",out);
}
结果:
2.
#include "stdio.h"
#include "string.h"
#include "math.h"
int main()
{
char a[50]={0};
char number[50]={0};
int i,len,k=0;
int out=1;
printf("please input a str:");
gets(a);
len=strlen(a);
for(i=0;i<len;i++)
if(a[i]>='0' && a[i]<='9')
number[k++]=a[i];
for(i=0;i<k;i++)
out+=(number[i]-'0')*pow(10.0,k-1-i);
printf("该字符串中的整数字符串转成整数再加上1后值为%d\n",out);
}
结果: