C语言编程题 求解

作者&投稿:溥亭 (若有异议请与网页底部的电邮联系)
求解这道C语言编程题~

#include #include #include int main(){char sub1[20],sub2[20],str[200],strtemp[200];scanf("%s %s",sub1,sub2);fflush(stdin);gets(str);strcpy(strtemp,str);int i,j;int len=strlen(str);int len_sub1=strlen(sub1);int len_sub2=strlen(sub2);for(i=0;i='A' && strtemp[i]='A' && sub1[i]<='Z'){sub1[i]+=32;}}int target_i=0;char target[500];j=0;for(i=0;i<len-len_sub1;i++){if(strtemp[i]==sub1[0]){int m=i;for(j=0;j<len_sub1;j++,m++){if(sub1[j]!=strtemp[m]){break;}}if(j==len_sub1){for(m=0;m<len_sub2;m++){target[target_i++]=sub2[m];}i=i+len_sub1;}}target[target_i++]=str[i];}target[target_i]='\0';printf("
%s
",target);return 0;}

有限定数多大吗?
#include
unsigned long long h2d(char *str) {

unsigned long long a;
sscanf(str, "%llx", &a);
return a;
}
int main() {
char hex[100];
scanf("%s", hex);
printf("%lld", h2d(hex));
return 0;
}

按照题意,表格使用结构链表实现。其中成员班级或工龄,使用自定义的联合体union(就是题目要求的共用体)。
函数异常不做处理,直接抛出,你需要可以在调用时判断处理异常。

#include <stdio.h>

#include <malloc.h>

typedef union info4

{

char cName[10];//班级名称

int wAge;//工龄

}IO4;

typedef struct stInfo

{

int id;//编号

char name[10];// 姓名

int pType;//职业类别:0表示学生,1表示教师

IO4 cwInfo;//对应职业类别的班级或工龄

struct stInfo *next;

}STINFO;

int inputInfo(STINFO **stHead,STINFO **stTail);//输入,调用一次输入一条信息,并生成或加入链表,成功返回1,失败返回0

void prfInfos(STINFO *stHead);// 打印链表

int main()

{

STINFO *stHead=NULL,*stTail=NULL;

int n=4;//测试就输入4个,需要自己改

while(n--)

if(!inputInfo(&stHead,&stTail))

{

printf("异常终止!
");

return 1;

}

prfInfos(stHead);

return 0;

}

void prfInfos(STINFO *stHead)// 打印链表

{

printf("编号   姓 名   职业 班级\\工龄
");

while(stHead->next)

{

printf("%d %9s %s",stHead->next->id,stHead->next->name,stHead->next->pType?"教师":"学生");

if(stHead->next->pType)

printf("%9d
",stHead->next->cwInfo.wAge);

else

printf("%9s
",stHead->next->cwInfo.cName);

stHead=stHead->next;

}

}

int inputInfo(STINFO **stHead,STINFO **stTail)//输入,调用一次输入一条信息,并生成或加入链表,成功返回1,失败返回0

{

static int id=1;

STINFO *head=*stHead,*tail=*stTail,*stNew=NULL;

stNew=(STINFO *)malloc(sizeof(STINFO));

stNew->pType=-1;

stNew->next=NULL;

if(!stNew)//抛出异常

return 0;

stNew->id=id++;

printf("请输入姓名:"),scanf("%9s",stNew->name);

if(getchar()!='
')//抛出异常

return 0;

while(stNew->pType<0 || stNew->pType>1)

printf("请输入职业编号(0:学生,1:教师):"),scanf("%d",&stNew->pType);

switch(stNew->pType)

{

case 0:printf("请输入学生所在班级名称:");

scanf("%9s",stNew->cwInfo.cName);

if(getchar()!='
')//抛出异常

return 0;

break;

case 1:printf("请输入教师的工龄:"),scanf("%d",&stNew->cwInfo.wAge);break;

}

if(head==NULL)

head=(STINFO *)malloc(sizeof(STINFO)),head->next=NULL;

if(head->next==NULL)

head->next=stNew;

else

tail->next=stNew;

tail=stNew;

*stHead=head,*stTail=tail;

return 1;

}




崇安区15383948108: 求解答一下C语言编程题,万分感谢 -
哈命蛇胆: 1)原代码x没声明,算法有错误.#include "stdio.h" int main(void){ int i,n; float s=0.0,x,t1=0.0,t2=1.0; printf("x,n=?"); scanf("%f,%d",&x,&n); for(i=1;i<=n;i++){ t1=t1+x; t2=t2/i; s=s+t1*t2; } printf("s=%f\n",s); return 0; }2)原代码书写不规范...

崇安区15383948108: 求解C语言题目编程序输入一个给定的数n后,输出的所有不超过n的,其平方由左右对称的数字组成的数.如输入30,输出1,2,3,11,22,26,因为它们的平方是1... -
哈命蛇胆:[答案] 需要判断回文,我已经尽量简单 #include int fun(int n) { int i, j, a[20]={0}; for(i=0; n; i++, n/=10) a[i] = n%10; for(j=0, i--; j

崇安区15383948108: C语言高手请进,几道题求解一、 使两个有序数列合成一个有序数列,合并后的数列仍然有序. 二、 编写函数,输入一个十进制数,将其转换为八进制、十... -
哈命蛇胆:[答案] 分数很少啊,随便给你一题的答案吧: #include int gcd(int a, int b) { int r = a%b; if (r == 0) return b; else return gcd(b, r); } int main( ) { printf("%d\n", gcd(100, 70)); return 0; }...

崇安区15383948108: C语言编程题求解 -
哈命蛇胆: #include<stdio.h>#include<math.h>#include<stdlib.h>/* 建立n个随机数序列d【】 */ int creat_random(int d[],int n) { int i,k; FILE *fp; srand((unsigned)time(NULL));for(i=0;i<n;i++) { d[i]=rand(); for(k=0;k<i;k++) if(d[k]==d[i]) { k=0; d[i]=rand(); } /*去...

崇安区15383948108: 求解C语言编程题. -
哈命蛇胆: 1.#include "stdio.h"#include "stdlib.h"#include "math.h" double func(double *content,int n) { double ave=0,s=0; int i; for(i=0;i<n;i++) ave+=*(content+i); ave/=n; for(i=0;i<n;i++) s+=pow(ave-*(content+i),2); s/=n; return s; } int main() { int n,i; ...

崇安区15383948108: C语言编程题,求解
哈命蛇胆: #include<stdio.h> int switc(int x) { if (x<0&&x>=-5) return 1; else if (x<10&&x>=0) return 0; } int main(int argc, char* argv[]) { int x,y; scanf("%d",&x); switch (switc(x)) { default: case 1:y='x';break; case 0:y='x-1';break; } putchar(y); return 0; }

崇安区15383948108: c语言编程问题求详解 -
哈命蛇胆: #include <stdio.h> int sum(int n) { int i, s = 0; for (i = 1; i <= n; i++) s += i; return s; } int main() { printf("1 + 2 + ... + 300 = %d\n", sum(300)); return 0; } #include <stdio.h> int main() { int i, j; for (i = 1; i <= 9; i++) { for (j = 1; j <= i; j++) printf("%d*%d=%-...

崇安区15383948108: C语言题目求解. -
哈命蛇胆: 程序1:#include#include void main() { double f,max=-999999; int x; for(x=1;x { f=x*x-5*x+sin(x); if(f>max)max=f; } printf("Max=%lf\n",max); } 程序2:#include#include void main() { int i,j,k=0,s; for(i=1999;i { j=i; s=0; while(j>0) {if(j%10==9)s++; j/=10; } ...

崇安区15383948108: 求解一道C语言编程题 -
哈命蛇胆: #include #define ARR_LEN 30 //数组长度 void main() { int num[ARR_LEN]; //数组 用来保存1到40之间的数 int index; //循环索引 int minNum=40; //将最小值初始化为40 int place; //位置 for(index=1;index { //如果输入的数不在范围内 则重新输...

崇安区15383948108: 解一道C语言编程题:
哈命蛇胆: 程序如下: #include<stdio.h>void main(){ char str[256]; int i,j; printf("输入一个字符串:\n"); for(i=0;(str[i]=getchar())!='\n';i++) ; for(j=0;j<=i-1;j++) { if(str[j]>='A'&&str[j]<='Z') str[j]+=32; else if(str[j]>='a'&&str[j]<='z') str[j]-=32; } printf("转换之后...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网