请编一个函数fun(oh lr*str),该函数的功能是把字符串中的内容逆置。 例如,字符串中原有的字符串为asdf9,则调用该函数后,串中的内容为9fdsa。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的花括号中填人所编写的若干语句。 试题程序: include<string.h> include<conio.h> include<stdio.h> define N 100 void fun(char * str) { } void main { char a[N]; FILE*out: printf("Enter a string:"); gets(a); printf("The origir al string is:"); puts(a); fun(a): printf("The string after modified:"); puts(a); strcpy(a,"Welcome!"); fun(a); ut=fopen("outfile.dat","w"); fprintf(out,"%s".a); fclose(out); }
第1题
中:成绩为60~69的人数存到b[0]中,成绩为70~79的人数存到b[1]中,成绩为80~89的人数存到b[2]中,成绩为90~99的人数存到b[3]中,成绩为100的人数存到b[4]中,成绩为60分以下的人数存到b[5]中。
例如,当a数组中的数据是:93、85、77、68、59、43、94、75、98,调用该函数后,b数组中存放的数据应是:1、2、1、3、0、2。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在横线上填入所编写的若于表达式或语句。
试题程序:
includedstdi0.h>
void fun(int a[],int b[],int n)
{
int i;
for(i=0;i<6;I++)
b[i]=0;
for(i=0:i<【1】 ;i++)
if(a[i]<60)
b[5]++;
【2】
b[(a[i]一60)/10]++;
}
void main
{
int i,a[100]={93,85,77,68,59,43,94,75,98),b[6];
fun(【3】 ,9);
printf("the result is:");
for(i=0;i<6;i++)
printf("%d",b[i]);
printf("\n,");
}
第2题
所有整数,把这些整数放在s所指的数组中,个数作为函数值 返回。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdio.h> define M 1000 int proc(int*S.int n) { int i,j,k,a,b,c; j=0; for(i=100;i<n;i++) { //****found**** k=n: a=k%10; k/=10; b=k%10; c=k/10; if(a==b+c) //****found**** s[j]=i: } return j; } void main { int a[M],m,num=0,i; do { printf("\nEnter m(<=1000):"); scanf("%d",&m); } while(m>1000); num=proc(a,m); printf("\n\nThe result:\n"); for(i=0;i<num;i++) printf("%5d",a[i]); printf("\n\n"); }
第3题
请编写函数fun,其功能是:计算并输出给定10个数的方差:
例如,给定的10个数为95.0、89.0、76.0、65.0、88.0、72.0、85.0、81.0、90.0、56.0,输出为s=11.730729。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第4题
的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdlib.h> include<stdio.h> include<eonio.h> float m[10]; //****found**** int proc(void) { int j; printf("In subfunc after calling\n"); for(j=0;j<10;j++) { //****found**** printf("%f",m[j]%5); } } void main { int i; printf("In main before calling\n"); for(i=0;i<10;i++) { m[i]=i+20; printf("%f",m[i]); } proc; printf("\nln main after calling\n"); for(i=0;i<10;i++) printf("%f",m[i]/5); }
第5题
三角形,则返回3;若是等腰三角形,则返回2;若能构成三角形则返回 1;若不能,则返回0。 例如,输入3个边长为3,4,5,实际输入时,数与数之间以Enter键分隔而不是逗号。请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdio.h> include<math.h> int proc(int a,int b,int c) { if(a+b>c&&b+c>aa+c>b) { if(a= =b&&b= =c) //****found**** return 1; else if(a= =b||b= =c||a= =c) return 2; //****found**** else return 3; } else return 0; } void main { int a,b,C,shape; printf("\nlnput a,b,C:"); scanf("%d%d%d",&a,&b,&c); printf("\na=%d,b=%d,c=%d\n",a,b,c); shape=proc(a,b,c); printf("\n\nThe shape:%d\n",shape); }
第6题
的字符和Str2所指字符串中的字符,按排列的顺序交叉合并到str所指数组中,过长的剩余字符接在str所指数组的尾部。例如,当str1所指字符串中的内容为ABCDEFG,str2 所指字符串中的内容为1234时,str所指数组中的内容应该为A483C2D1EFG;而当str1所指字符串中的内容为1234,str2所指字符串中的内容为ABCEDFG时,str所指数组中的内容应该为1G2F31:4DCBA。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdlib.h> include<conio.h> include<stdio。h> include<string.h> void proc(char*strl,char*str2,char*str) { int i,j;char ch; i=0;j=strleu(str2)-1; //****found**** while(i>j) { ch=str2[i];str2[i]=str2[j];str2[j]=ch; i++;j--; } while(*str1||*str2) { if(*str1){*str=*str1;str++;str1++;) if(*str2){*str=*str2;str++;str2++;) } //****found**** *str=0: } void main { char s1[100],s2[100],t[200]; system("CLS"); printf("\nEnter s1 string:"); scanf("%s",sl); printf("\nEnter s2 string:"); scanf("%s",s2); proc(s1,s2,t); printf("\nThe result is:%s\n",t); }
第7题
升序排序后输出。 例如,输入opdye,则应输出deopy。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<string.h> include<stdlib.h> include<conio.h> include<stdio.h> //****found**** int proc(char str[]) { char c; unsigned i,j; for(i=0;i<strlen(str)-1;i++) for(j=i+1;j<strlen(str);j++) if(str[i]>str[j]) { c=str[j]: //****found**** str[j]=str[i++]; str[i]=c; } } void main { char str[81]; system("CLS"); printf("\nPlease enter a character string:"); gets(str); printf("\n\nBefore sorting:\n%s",str); proc(str); printf("\nAfter sorting decendingly:\n %s",str); }
第8题
连续出现的最长长度(即0字符的个数),如果有几个0字符串长度相同,只记录最后一个0字符串的相关信息。通过m和k返回最长0字符串的长度和最后0字符的下标。例如,如果输入“01001000”,结果为:0字符串最长长度为3,起始和结尾下标依次为5、7。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define N 80
void fun (【 】)
{
int i, j=0;
int bb[N];
char *p=str;
*m=0;
*k=0;
for(i=0;i<N;i++)
bb[i]=0;
i=0;
while(*(p+i))
{
if(*(p+i)='0')
{
【 】
i++;
}
else
{
j++;
i++;
}
if (【 】)
{
*m=bb[j];
*k=i-1;
}
}
}
main()
{
char str[N];
int m,n,k;
clrscr();
printf("***input the original string
***\n");
gets(str);
printf("***The Original string ***\n");
puts(str);
fun(str,&m,&k);
printf("\nThe length of '0' is :
%d\n",m);
printf("*** The suffix of character
***\n");
printf(" %d,%d",k-m+1,k);
}
第9题
1。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio. h>
define N 10
main ( )
{
int bb[N] [N];
int i, j,n;
clrscr ();
printf (" \nInput n:\n");
scanf ("%d", &n);
for (i=0; i<n; i++)
for (j=0; j<n; j++)
{
【 】;
if (i==j)
bb[i] [j]=【 】;
if (【 】)
bb[i] [j]=1;
}
printf(" \n***** the result ***** \n");
for (i=0; i<n; i++)
{
printf (" \n\n");
for (j=0; j<n; j++)
printf ("%4d",bb [i] [j] );
}
}
第10题
的实数个数。
例如,n=8时,输入:193.199,195.673,195.757,196.051,196.092,196.596,196.579,196.763
所得平均值为:195.838745,在平均值以上的实数个数应为:5
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!