AI智能
改变未来

有关C++程序设计基础的各种考题解答参考汇总

早先年考研的主考科目正是【算法与数据结构】,复习得还算可以。也在当时[百度知道]上回答了许多相关问题,现把他们一起汇总整理一下,供读者参考。

 

【1】

原题目地址:https://zhidao.baidu.com/question/1574956570322831900.html?entry=qb_uhome_tag

题目:C语言的题目,求大神来看看小学生算术学习系统。不断的从键盘输入两个整数级一个运算符(+-*/)之一,并输入计算结果。若计算结果正确,则显示“很好,做对了。”负责献世“做错了,再做一次“。系统规定,只能输入三次答案。当第三次输入答案任然错误时,系统将显示正确答案。本系统要求有”是否继续”的提示,用户输入“y”,表示继续,输入“n”表示结束

答:

#include <stdio.h>#include <time.h>#include <windows.h>#include <stdlib.h>int main(){int a,b,Suan;int sum;       //用户输入答案int C;         //正确答案int D;         //正确余数int yu = 0;          //输入的余数int t = 0;           //开关变量(求余数)int i = 3;int temp = NULL;char Insert = NULL;srand(time(NULL));Q:   a = rand()%100;b = rand()%100;Suan = rand()%100;t = 0;if(Suan <=25){C = a+b;printf("%d+%d=? :\\n",a,b);temp = 1;D = 0;yu = 0;}else if(Suan > 26 && Suan <= 50){C = a-b;printf("%d-%d=? :\\n",a,b);temp = 2;D = 0;yu = 0;}else if(Suan > 50 && Suan <= 75){C = a*b;printf("%d*%d=? :\\n",a,b);temp = 3;D = 0;yu = 0;}else if(Suan > 75 && Suan <= 100){C = a/b;D = a%b;t = 1;printf("%d/%d=? (商):\\n",a,b);temp = 4;}A:   if(5 == temp){printf("%d+%d=? :\\n",a,b);}if(6 == temp){printf("%d-%d=? :\\n",a,b);}if(7 == temp){printf("%d*%d=? :\\n",a,b);}if(8 == temp){printf("%d/%d=? (商):\\n",a,b);}if(temp <= 4){temp++;temp++;temp++;temp++;}scanf("%d",&sum);if(t == 1){printf("余数多少:");scanf("%d",&yu);}printf("\\n---------------------\\n");if(C == sum && D == yu)printf("很好,做对了。\\n");else{if(1 != i){printf("做错了,再做一次!(你还有%d次机会)\\n",i-1);i--;goto A;}else{if(t == 0)printf("做错了!正确答案是 %d!\\n",C);else{printf("做错了!正确答案(商)是 %d!\\n",C);printf("(余数)是 %d!\\n",D);}//i = 3;}}i = 3;printf("-----------------------------------------------\\n");printf("是否继续<y/n>:\\n");P:       scanf("%c",&Insert);if(\'y\' == Insert)goto Q;if(\'n\' == Insert)exit(-1);else{Insert = NULL;goto P;}system("pause");return 0;}

 

【2】

原题目地址:https://zhidao.baidu.com/question/1495135027232307579.html?entry=qb_uhome_tag

题目:求解c语言指针问题

#include<stdio.h>#include<conio.h>#define N 2#define M 4double *calculate1(double (*p)[M], double *p1) {int i, j;double s=0;for (j=0; j<M; j++) {for (i=0; i<N; i++) {s+=*(*p+j);p++;}for (i=0; i<N; i++) p--;*(p1+j)=s;s=0;}p1=p1-M;return p1;}void main() {int m;double score[M]={0, 1, 2, 3, 4, 5, 6, 7}, sbj[M], (*p)[M]=score, *p1=sbj;p1=calculate1(p, p1);for (m=0; m<M; m++) printf("\\n第%d科总分为%.1lf\\n", m+1, *(p1+m));}

score
[M]表示N个学生的M门科目的成绩,算出各科的总分为什么结果是这样

答:

#include<stdio.h>#include<conio.h>#include <windows.h>#define N 2#define M 4void calculate(double (*p)[M],double *p1){int i,j;double s=0;/*for(i=0;i<N;i++){for(j=0;j<M;j++){printf("%f\\t",*(*(p+i)+j));}putchar(10);}*/for(i=0;i<M;i++){for(j=0;j<N;j++){//printf("%f\\t",*(*(p+j)+i));s+=*(*(p+j)+i);}*(p1+i)=s;s=0;}return;}int main(){int m;double score[M]={0,1,2,3,4,5,6,7},sbj[M],(*p)[M]=score,*p1=sbj;calculate(p,p1);for(m=0;m<M;m++)printf("\\n第%d科总分为%.1lf\\n",m+1,*(p1+m));system("pause");return 0;}

我读不懂你的程序,很多都不需要的。你可以参照我写的!有问题可以追问!

 

【3】

原题目地址:https://zhidao.baidu.com/question/1895405030720891420.html?entry=qb_uhome_tag

题目:求C语言大神助攻解决这几道问题

答:

/*******//***1***//*******/#include<stdio.h>#include <windows.h>int Judge(char a[],char b[]){int i,j;for(i=0,j=0; a[i]!=\'\\0\' ; i++,j++){if(a[i] == b[j])continue;if(a[i] > b[j])return 1;if(a[i] < b[j])return -1;}return 0;}int main(){int m = NULL;char str1[5] = "abc";char str2[5] = "abb";puts(str1);putchar(10);puts(str2);m = Judge(str1,str2);if(m == 1)printf("[>]\\n");else if(m == -1)printf("[<]\\n");elseprintf("[=]\\n");system("pause");return 0;}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*******//***2***//*******/#include<stdio.h>#include <windows.h>int main(){float sum = 1.0;int ss;int s=1,s1=1;printf("sum=1/1");while(1.0/s >= 1e-6){sum += 1.0/s;printf(" +1/%d",s);ss = s1;s1 = s;s += ss;}sum += 1.0/s;printf(" +1/%d",s);printf(" = %f\\n",sum);system("pause");return 0;}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*******//***3***//*******/#include<stdio.h>#include <windows.h>void Func(int a[][4]){int i,j,t = 0;for(i=0; i<4; i++){for(j=0; j<4; j++){if(a[j][i] > 0)t++;}if(t>=1){printf("%d\\n",i);t = 0;}}return;}int main(){int a[4][4];int i,j;for(i=0; i<4; i++)for(j=0; j<4; j++)scanf("%d",&a[i][j]);for(i=0; i<4; i++){for(j=0; j<4; j++)printf("%d\\t",a[i][j]);putchar(10);}putchar(10);Func(a);system("pause");return 0;}/*******//***4***//*******/#include <stdio.h>#include <windows.h>void Connect(char a[],char b[],char c[]){int i,j;for(i=0; a[i]!=\'\\0\'; i++)c[i] = a[i];for(j=0; b[j]!=\'\\0\'; j++)c[i++] = b[j];c[i]=\'\\0\';return;}int main(){int m = NULL;char str1[5] = "abc";char str2[10] = "bcde";char str3[20];printf("str1=");puts(str1);putchar(10);printf("str2=");puts(str2);putchar(10);Connect(str1,str2,str3);printf("str3=");puts(str3);system("pause");return 0;}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*******//***5***//*******/#include<stdio.h>#include <windows.h>int main(){int i;float sum=0;double f1=1.0,f2=1.0,t;printf("sum=");while(sum<=100.0){sum += f1/f2;printf(" +%f/%f",f1,f2);t=f2;f2=f2+f1;f1=t;}printf("= %.2f\\n",sum);system("pause");return 0;}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*******//***6***//*******/#include<stdio.h>#include <windows.h>void Func(int a[][4]){int i,j,t = 0;for(i=0; i<4; i++){for(j=0; j<4; j++){if(a[i][j] > 0)t++;}if(t>=1){printf("%d\\n",i);t = 0;}}return;}int main(){int a[4][4];int i,j;for(i=0; i<4; i++)for(j=0; j<4; j++)scanf("%d",&a[i][j]);for(i=0; i<4; i++){for(j=0; j<4; j++)printf("%d\\t",a[i][j]);putchar(10);}putchar(10);Func(a);system("pause");return 0;}

请你叫我雷锋,帮你做了这么多题!有问题欢迎追问!(哈哈,当时心情肯定不错,帮忙做了那么多题目,啊哈哈~)

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 有关C++程序设计基础的各种考题解答参考汇总