请编写一个函数void fun(char*ss),其功能是:将字符串 ss中所有下标为偶数位置上的字母转化为大写(若该位置上不是字母,则不转换)。
例如,若输入abc4Efg,则应输出AbC4EfG。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio. h>
void fun (char *ss)
{
}
main ()
{
char tt[51];
clrscr ();
printf("Please enter an character string
within 50 characters:\n");
gets (tt);
printf ("\n\nAfter changing, the string\n
%s", tt);
fun (tt);
printf("\nbecomes\n \%s",tt);
}
第1题
请补充函数fun(),该函数的功能是把数组aa中的奇数元素按原来的先后顺序放在原数组后面。
例如,输入“33,67,42,58,25,76,85,16,41,56”,输出结果“42,58,76,16,56,33,67,25,25,41。
注意:部分源程序给出如下。
请勿改动主函数main和具他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 10
void fun(int aa[])
{
int i, j=0,k 0;
int bb IN];
for (i 0; i<N; i++)
{
if (【 】)
bb[k++] aa[i];
else
aa [j++] =aa Ii];
for(i=0; i<k;【 】)
aa[j] bb[i];
}
main ( )
{
int i;
int aa[N]={33, 67, 42,58,25, 76, 85, 16,
41,56};
clrscr ();
printf("\n*** original list ***\n");
for (i=0; i<N; i++)
printf("%4d", aa[i]);
fun (aa);
printf("\n*** new list ***\n");
for (i=0; i<N; i++)
printf("%4d", aa[i]);
}
第2题
请补充main函数,该函数的功能是:求1+21+3!+…+N!的和。
例如, 1+2!+3!+...+5!+6!的和为873。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
main ( )
{
int i, n;
long s=0, t=l;
clrscr ();
printf ("\nInput n: \n");
scanf ("%d",【 】);
for (i=l; i<=n; i++)
{
t=【 】;
s=【 】;
}
printf ("1 ! +2 ! +3 !... +%d! =%ld\n", n, s);
}
第3题
入法的基本方法是:先对字符串中的头两个元素进行排序,然后把第3个字符插入到前两个字符中,插入后前3个字符依然有序;再把第4个字符插入到前3个字符中,待排序的字符串已在主函数中赋予。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
include <String.h>
include <stdio.h>
define N 80
void insert(char *aa)
{ iht i, j, n; char ch;
n=strlen (aa);
for (i=1; i<n; i++)
/**********************************/
{ c=aa[i];
j=i-1;
while ((j>=0) && (ch<aa [j] ))
{ aa [j+l]=aa[j];
j--;
}
aa [j+l]=ch;
}
}
main ( )
{ char a [N] = "QWERTYUIOPASDFGHJKIMNBVCXZ";
int i;
printf("The original string: %s\n",a);
insert (a);
printf("The string after sorting:
%s\n\n", a);
}
第4题
否则函数返回字符串:no!,并在主函数中输出。所谓回文即正向与反向的拼写都一样,例如:abcba。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<string.h>
include<stdio.h>
char *fun(char*str)
{
char *p1,*p2;
int i, t=0;
p1=str;p2=str+strlen(str)-1;
for (i=0;【 】;i++)
if(【 】)
{
t=1;
break;
}
if (【 】)
return("yes!");
else
return("no!");
}
main()
{
char str[50];
printf("Input;");
scanf("%s",str);
printf("%s\n",fun(str));
}
第5题
降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,敢不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
/*************found**************/
int fun(char t[])
{
char c;
int i,j;
for(i=0;i<strlen(t)-1;i++)
for(j=i+1;i<strlen(t);j++)
if(t[i]<t[j])
{
c=t[j];
/*************found**************/
t[i]=t[i++];
t[i]=c;
}
}
main()
{
char s[81];
clrscr();
printf("\nPlease enter a character
string:");
gets(s);
printf("\n\nBefore sorting:\n%S",s);
fun(s);
printf("\nAfter sorting decendingly:\n
%s",s);
}
第6题
偶数的字符保存在字符串str2中并输出。例如,当str1=“cdefghij”,则 str2=“cegi”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define LEN 80
main()
{
char str1[LEN],str2 [LEN];
char *p1=str1,*p2=str2;
int i=0,j=0;
clrscr();
printf("Enter the string:\n");
scanf(【 】);
printf("***the origial string***\n");
while(*(p1+j))
{
printf("【 】",*(p1+j));
j++;
}
for(i=0;i<j;i+=2)
*p2++=*(str1+i);
*p2='\0';
printf("\nThe new string is:%s\n", 【 】 );
}
第7题
写代表最大值的输出项。
include<stdio.h>
main( )
{int a[10],*p,*S;
for(p=a;p-a<10;p++)scanf(”%d”,p);
for(p=a,s=a;p-a<10;p++)if(*p>*s)s=p;
printf(”max=%d\n”,________);
}
第8题
下列给定的程序中,函数fun()的功能是:用选择法对数组中的n个元素按从小到大的顺序进行排序。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
define N 20
void fun(int a[],int n)
{int i,j,t,p;
for (j=0;j<n-1;j++)
/*************found**************/
{p=j
for(i=j;i<n;i++)
if(a[i]<a[p])
/*************found**************/
p=j;
t=a[p]; a[p]=a[j]; a[j]=t;
}
}
main()
{int a[N]={9.6,8,3,-1},i,m=5;
printf("排序前的数据: ");
for(i=0;i<m;i++) printf("%d",a[i]);
printf("\n");
fun(a,m);
printf("排序后的顺序: ");
for(i=0;i<m;i++) printf("%d",a[i]);
printf("\n");
}
第9题
下列给定程序中函数fun()的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
long fun(long num)
{
/*+**+*+*+*found************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/*********+found*+**+*+******/
}while(num)
return(k);
}
main()
{
long n;
clrscr();
printf("\Please enter a number:");
scanf("%ld",&n);
printf("\n%ld\n",fun(n));
}
第10题
下列给定程序中,函数fun()的功能是:根据整型参数m,计算如下公式的值。
y=1/(100×100)+1/(200×200)+1/(300×300)+…+1/(m×m)
例如,若m=2000,则应输出0.000160。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio. h>
/*************found**************/
fun (int m)
{ double y=0, d;
int i;
/*************found**************/
for (i=100, i<=m, i+=100)
{d= (double) i* (double) i;
y+=l. 0/d;
}
return (y);
}
main ( )
{ int n=2000;
clrscr();
printf("\nThe result is %lf\n",fun(n));
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!