更多"请补充main函数,该函数的功能是:输入两个正整数m和n,求这两个数的"的相关试题:
[填空题]请补充main函数,该函数的功能是:输入两个正整数m和n,求这两个数的最大公约和最小公倍数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
main ( )
{
int a, b, n, m, t;
clrscr ( );
printf ("/nInput two numbers: /n");
scanf ("%d, %d", &n, &m);
if (n<m)
{
a=m;
b=n;
}
else
{
a=n;
b=m;
}
while( 【1】 )
{
t= 【2】
a=b;
b=t;
}
printf ("greatest con. non divisor:
%d/n", a);
printf ("least common multiple:
%d/n", 【3】 );
}
[简答题][函数2.1说明]
下面程序的功能是计算x和y的最小公倍数。
[函数2.1]
main( )
int m,n,d,r;
seanf("%d %d",&m,&n);
if(m<n) r=m;m=n;n=r;
(1) ;
while (d%n! =0) (2) ;
printf("%d/n",d);[函数2.2说明]
下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。
[函数2.2]
#include <stdio.h>
main( )
char c,preChar=’/0’;
c = getchar( );
while(c! = ’.’)
if( (3) ) putchar(c);
else if(preChar! =’ ’) putchar(c);
(4) ;
c= (5) ;
[填空题]下列给定程序中,函数proc( )的功能是计算正整数m各位上数字的平方和。
例如,输入498,则输出应该是161。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main( )函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
long proc(long m)
{
//****found****
long sum=1;
do
{
sum+=(m%10)*(m%10);
m/=10;
//****found****
}
while(m)
return(sum);
}
void main( )
{
long n;
system("CLS");
printf("Please enter a number:");
scanf("%1d",&n);
printf("/n%1d/n",proc(n));
}
[填空题][函数2.1说明]
求任意两个正整数的最大公约数的欧几里德算法。用辗转相除法求正整数m和n的最大公约数,并返回该公约数。
[函数2.1]
void func1(int m, int n) {
r=m% n;
while(r<>0) {
(1) ;
n=r;
(2) ;
}
return n;
}
[函数2.2说明]
判断101~200之间有多少个素数,并输出所有素数。用一个数分别去除2到sqrt (这个数),如果能被整除,则表明此数不是素数,反之是素数。
[函数2.2]
void func2 ( ) {
int m, i, k, h=0,leap=1;
printf ( "/n" );
for ( m=101;m<=200;m++ )
{ (3) ;
for (i=2;i<=k; i++ )
if( (4) )
{leap=0;break;}
if ( leap )
{printf ( "%-4d",m );
(5) ;
if ( h%10==0 )
printf ( "/n" );
}
leap=1;
}
printf ( "/n The total is %d", h );
}
[填空题][函数2.1说明]
求任意两个正整数的最大公约数的欧几里德算法。用辗转相除法求正整数m和n的最大公约数,并返回该公约数。
[函数2.1]
void func1(int m, int n)
r=m% n;
while(r<>0)
(1) ;
n=r;
(2) ;
return n;
[函数2.2说明]
判断101~200之间有多少个素数,并输出所有素数。用一个数分别去除2到sqrt (这个数),如果能被整除,则表明此数不是素数,反之是素数。
[函数2.2]
void func2 ( )
int m, i, k, h=0,leap=1;
printf ( "/n" );
for ( m=101;m<=200;m++ )
(3) ;
for (i=2;i<=k; i++ )
if( (4) )
leap=0;break;
if ( leap )
printf ( "%-4d",m );
(5) ;
if ( h%10==0 )
printf ( "/n" );
leap=1;
printf ( "/n The total is %d", h );
[填空题]请补充函数fun( ),该函数的功能是:把从主函数中输入的字符串str2倒置后接在字符串str1后面。
例如:str1=“How do”,str2=“od uoy”,结果输出:“How do you do”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define N 40
void fun(char *str1,char *str2)
int i=0,j=0,k=0,n;
char ch;
char *p1=str1;
char *p2=str2;
while(*(p1+i))
i++;
while(*(p2+j))
j++;
n= 【1】 ;
for(;k=j/2;k++,j--)
ch=*(p2+k);
*(p2+k)=*(p2+j);
*(p2+j)=ch;
【2】 ;
for(; 【3】 ;i++)
*(p1+i)=*p2++;
*(p1+i)=’/0’;
main( )
char str1[N],str2[N];
int m,n,k;
clrscr( );
printf("***Input the string str1 & str2
***/n");
printf("/nstr1:");
gets(str1);
printf("/nstr2:");
gets(str2);
printf("***The string str1 & str2 ***/n");
p
[填空题]请补充函数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 *p1=str1;
char *p2=str2;
while( 【1】 )
i++;
for( ; 【2】 ;i++)
*(p1+i)= 【3】 ;
*(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);
}
[简答题]填空题
请补充函数fun( ),该函数的功能是:把从主函数中输入的字符串str2倒置后接在字符串str1后面。
例如:str1=“How do”,str2=“od uoy”,结果输出:“How do you do”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define N 40
void fun(char *str1,char *str2)
{
int i=0,j=0,k=0,n;
char ch;
char *p1=str1;
char *p2=str2;
while(*(p1+i))
i++;
while(*(p2+j))
j++;
n=【1】;
for(;k<=j/2;k++,j--)
{
ch=*(p2+k);
*(p2+k)=*(p2+j);
*(p2+j)=ch;
}
【2】;
for(;【3】;i++)
*(p1+i)=*p2++;
*(p1+i)=’’/0’’;
}
main( )
{
char str1[N],str2[N];
int m,n,k;
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);
}
[填空题]请补充函数fun( ),该函数的功能是:把从主函数中输入的由数字字符组成的字符串转换成—个无符号长整数,并且逆序输出。结果由函数返回。
例如,输入: 1 2 3 4 5 6,结果输出:6 5 4 3 2 1。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#include<string.h>
unsigned long fun(char *s)
unsigned long t=0;
int k;
int i=0;
i=strlen(s);
for( 【1】 ;i>=0;i--)
k= 【2】 ;
t= 【3】 ;
return t;
main( )
char str[8];
clrscr( );
printf("Enter a string made up of’0’to
’9’digital character:/n");
gets(str);
printf("The string iS:%S/n",str);
if(strlen(str)>8)
printf("The string is too long!");
else
printf("The result:%lu/n",
fun(str));
[填空题]下面程序的功能是对输入的正整数M和K(M>K)通过调用过程SUB计算并显示S的值,这里
S=K!+(K+1)!+……+M!,请填空:
CLEAR
INPUT "输入K值:" TO K
INPUT " 输入M值:" TO M
①
FOR R = K TO M
DO SUB ②
S = S+A
ENDFOR
" S的值为:" , S
RETURN
③
PARAMETERS P , N
P = 1
FOR L=1 TO N
P = P*L
ENDFOR
RETURN
[填空题]请补充函数fun( ),该函数的功能是:把从键盘输入的3个整数按从小到大输出。
例如:输入“33 78 25”,结果输出“25 33 78”。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的横线上填入所编写的若干表达式或语句。
试题程序:
# include<stdio. h>
# include<conio. h>
main( )
{
int x,y, z,t;
clrscr ( );
printf ("Input x, y, z/n");
scanf ("%d%d%d", &x, &y, &z);
if( 【1】 )
{
t=x;
x=y;
y=t;
}/*变换x, y的值*/
if( 【2】 )
t=z;
z=x;
x=t;
}/*交换x, z 的值*/
if( 【3】 )
{
t=y;
y=z;
z=t;
}/*变换 z, y 的值*/
printf("******the result*******/n");
printf("from small to big: %d %d %d/n",
x, y, z);
}
[填空题]请补充函数fun( ),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
int fun (char s[],char ch)
int i=0, n=0;
while( 【1】 )
if( 【2】 )
n++;
i++;
【3】 ;
main ( )
int n;
char str[N], ch;
clrscr ( );
printf ("/nInput a string: /n");
gets (str);
printf ("/nInput a charactor: /n" ;
scanf ("%c", &ch);
n=fun (str, ch);
printf("/nnumber of %c:%d", ch, n);
[填空题]请补充函数proc( ),该函数的功能是:删除字符数组中小于指定字符的字符,指定字符从键盘输入,结果仍保存在原数组中。
例如,输入“abcdefghij”,指定字符为“f”,则结果输出“fghij”。
注意:部分源程序已给出。
请勿改动主函数main和其他甬数中的任何内容。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define M 80
void proc(char str[], char ch)
int i=0, j=0;
while(str[i])
if(str[i]<ch)
(1) ;
else
(2) ;
i++;
(3) ;
void main( )
char str[N], ch;
system("CLS");
printf("/n Input a string: /n");
gets(str);
printf("/n***original string***/n");
puts(str);
printf("n Input a charactor:/n");
scanf("%c", &ch);
proc(str, oh);
printf("/n***new string***/n");
puts(str);