请补充main函数,该函数的功能是:输入两个正整数numl和num2,求这两个数的最大公约和最小公倍数。
例如,若输入的两个正整数为12,4,则它们的最大公约数为12,最小公倍数为4。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填人所编写的若干表达式或语句。
试题程序:
include<stdlib.h>
include<stdio.h>
void main
{
int a,b,numl,num2,t;
system("CLS"):
printf("\nInput two numbers:\n");
scanf("%d,%d",&numl,&num2);
if(numl<num2)
{
a=num2;
b=num1:
}
else
{
a=num1;
b=num2;
}
while(【1】)
{
t=【2】
a=b;
b=t:
}
printf(“greatest common divisor:
%d\n",a);
printf("least common multiple:
%d\n",【3】;
}
第1题
例如,若输入的两个正整数为12,4,则它们的最大公约数为12,最小公倍数为4。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填人所编写的若干表达式或语句。
试题程序:
include<stdlib.h>
include<stdio.h>
void main
{
int a,b,numl,num2,t;
system("CLS"):
printf("\nInput two numbers:\n");
scanf("%d,%d",&numl,&num2);
if(numl<num2)
{
a=num2;
b=num1:
}
else
{
a=num1;
b=num2;
}
while(【1】)
{
t=【2】
a=b;
b=t:
}
printf(“greatest common divisor:
%d\n",a);
printf("least common multiple:
%d\n",【3】;
}
第2题
第3题
例如,若nmnl和num2分别为49和21,则输出的最大公约数为7;若num1和num2分别为27和81,
则输也的最大公约数为27。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或硼行,也不得更改程序的结构!
试题程序:
第4题
注意:部分源程序已给出。
请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。
试题程序:
include<stdio. h>
include<conio. h>
define MAXNUM 200
int xx [MAXNUM];
int totNum=0;
int totCnt=0;
double totPjz=0.0;
int ReadDat (void);
void WriteDat (void)
void CalValue (void)
{
void main ( )
{
int i;
clrscr ( );
for ( i=0; i<MAXNUM; i++ )
xx[i]=0;
if (ReadDat ( ) )
{
printf ("数据文件IN65.DAT不能打开! \007\")
return;
}
CalValue ( );
printf ( "文件IN65.DAT中共有正整数=%d个\n",totNum);
printf ( "符合条件的正整数的个数=%d个\n", totCnt)
printf ( "平均值=%. 21f\n", totPjz);
WriteDat ();
}
int ReadDat (void)
{
FILE *fp;
int i=0;
if ( ( fp= fopen ( "IN65. DAT", "r" ) ) ==NULL)
return 1;
while ( ! feof (fp))
{
fscanf (fp, "%d", &xx [i++] );
}
fclose (fp);
return 0;
}
void WriteDat (void)
{
FILE *fp;
fp=fopen ("OUT65. DAT", "w" );
fprint f (fp, "%d\n%d\n%. 21f\n", totNum, totCnt,totPjz);
fclose (fp);
}
第5题
请补充main函数,该函数的功能是:从键盘输入两上字符串并分别保存在字符数组str1和str2中,用字符串str2替换字符串str1前面的所有字符,注意,str2的K度不大于str1,否则需要重新输入。
例如,如果输入strl;=“abced”,str2=“fk”,则输出“fkced”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<string. h>
main ()
{
char strl [ 81], str2 [ 81 ];
char *pl=strl, *p2=str2;
clrscr ();
do
{
printf(" Input strl tn");
gets (strl);
printf(" Input str2 In");
gets (str2);
}while(【 】);
while(【 】)
*p1++=*p2++;
printf(" Display strl \n");
puts (【 】)
}
第6题
请补充函数proc,该函数的功能是:把从主函数中输入的由数字字符组成的字符串转换成一个无符号长整数,并且逆序输出。结果由函数返回。例如,输入:1234567,结果输出:7654321。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的横线上填人所编写的若干表达式或语句。 试题程序: include include include stdio.h> include unsigned long proc(char*str) { unsigned long t=0: int k: int i=0; i=str|en(str); for(【1】 ;i>=0;i--) { k= 【2】 ; t= 【3】 ; } return t; } void main { char str[8]; system("CLS"); printf("Enter a string made up of0to 9 digital character:\n"); gets(str); printf("The string,is:%s\n",str); if(strlen(str)>8) printf("The string is too tong!"); else printf("The result:%1u\n", proc(str)); }
第7题
请编写函数fun(),该函数的功能是:将两个两位数的正整数a,b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。
例如,当a=45时,b=12,调用到该函数后,c=5142。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include<conio.h>
void fun(int a ,int b, long *c)
{
}
main ()
{
int a,b;
long c;
clrscr();
printf("Input a ,b:");
scanf(,%d%d",&a,&b);
fun(a,b,&c);
printf("The result is :%ld\n",c);
}
第8题
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2接在字符串str1的后面。
例如:str1=“How do”,str2=“you do?”,结果输出: How do you do?
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define N 40
void fun(char*str1,char *str2)
{
int i=0;
char *pl=str1;
char*p2=str2;
while(【 】)
i++;
for(;【 】;i++)
*(p1+i)=【 】;
*(p1+i)='\0';
}
main()
{
char str1[N],str2[N);
clrscr();
printf("*****Input the string str1 & Str2*****\n");
printf("\nstr1:");
gets(str1);
printf("\nstr2:");
gets(str2);
printf("**The string str1 & str2**\n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*****The new string *****\n");
puts(str1);
}
第9题
请编写函数fun,它的功能是:求任意两个正整数的最小公倍数和最大公约数,最小公倍数放在指针变量bei所指的变量中,最大公约数放在指针变量yue所指的变量中。
注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
vOid fun(int m,int n,int*bei,int*yue)
{int s=l,i;
if(m>n){s=m;m=n;n=S;}
for(i=2,s=1;i<m i++)
if((m%i=0)&&(n%i=0))
{
}
*yue=s;
*bei=S*m*n;
}
main()
{int a,b,beishu,yueshu;
chscr();
printf("please input a,b:");scanf("%d,%d,"&a,&b);
fun(a,b,&beishu,&yueshu);
printf("a,b beishu:%d\n",beishu);
printf("a,b yueshu:%d\n",Yueshu);
}
第10题
请补充函数fun(),该函数的功能是:把一个字符串中的字符(字母)按从小到大排序,并把这个全部由字母组成的字符串保存在原串中,函数返回这个字符串的长度。例如;输入“cixbr2.3”,如果为bcirx,字符串长度为5。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
include <stdio.h>
define N 20
int fun (char *str)
{
int i=0,j=0,k=-0,m=0;
char t;
char *p=str;
while(*p)
{
if((*p>='A'&&*p<='Z')||(*p>='a'
&&*p<='z'))
【 】
p++;
}
*(str+i)='\0';
【 】;
while(*(p+j))
{
k=j;
【 】;
while (*(p+k))
{
if(*(p+k)<*(str+m)
{
t=*(str+m);
*(str+m)=*(p+k);
*(p+k)=t;
}
k++;
}
j++;
}
return i; }
main()
{
char str[81];
iht n;
clrscr();
printf("Input the original string ");
gets(str);
printf("*** The Original string ***In");
puts(str);
printf("*** The nwe string ***\n");
n=fun(str);
puts(str);
printf("***The length of new string is:
%d***\n",n);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!