更多"请补充main函数,该函数的功能是:输入两个正整数m和n,求这两个数的"的相关试题:
[简答题][函数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) ;
}
}
[简答题][函数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) ;
[简答题]
【说明】
函数int funl (int m,int n)的功能是:计算并返回正整数m和n的最大公约数。
【函数2.1】
int funl (iht m,int n){
while( (1) ) {
if(m>n) m=m-n;
else n=n-m;
}
(2) ;
}
【函数2.2说明】
函数long fun2(char*str)的功能是:自左至右顺序取出非空字符串str中的数字字符形成一个十进制整数(最多8位)。
例如,若字符串str的值为“f3g8d5.ji2e3p12fkp",则函数返回值为3852312。
【函数2.2】
long fun2 (char*str)
int i=0;
long k=0;
char*P=str;
while (*p!=’/0’&& (3) )
if (*p>=’0’&&*p<=’9’)
k= (4) +*p-’0’;
++i;
}
(5) ;
}
return k;
}
[填空题][函数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
#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( ),该函数的功能是:把从主函数中输入的字符串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");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*** The new string ***/n");
puts (str1);
}
[填空题]请补充函数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( ),该函数的功能是:把从主函数中输入的由数字字符组成的字符串转换成—个无符号长整数,并且逆序输出。结果由函数返回。
例如,输入: 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));
[填空题]请补充函数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);
[填空题]从键盘输入一组小写字母,并保存在字符数组str中。请补充函数fun( ),该函数的功能是:把字符数组str中ASCII码为奇数的小写字母转换成对应的大写字母,结果仍保存在原数组中。
例如,输入“abcdefg”,输出“AbCdEfG”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 80
void fun(char s[])
{
int i;
for( 【1】 ; 【2】 ;i++)
{
if( 【3】 )
s[i]-=32;
}
}
main( )
{
char str[N];
clrscr( );
printf("/n lnput a string:/n");
gets(str);
printf("/n*** original string ***/n");
puts (str);
fun (str);
printf("/n*** new string ***/n");
puts (str);
}
[填空题]请补充main函数,该函数的功能是:从键盘输入一组整数,使用条件表达式找出最大的整数。当输入的整数为0时结束。
例如,输入1,2,3,5,4,0时,最大的数为5。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写出的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define N 100
main( )
{
int num[N];
int i=-1;
int max=0;
clrscr( );
printf("/nInput integer number:/n");
do
{
i++;
printf("num[%d]=",i);
scanf("%d", 【1】 );
max= 【2】 num[i]:max;
}while ( 【3】 );
printf("max=%dkn",max);
}
[填空题]请补充main函数,该函数的功能是:从键盘输入若干字符放到一个字符数组中,当桉回车键时结束输入,最后输出这个字符数组中的所有字符。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<ctype.h>
main( )
int i=0;
char a [81];
char *p=s;
clrscr ( );
printf" Input a string /n");
for (i=0; i<80; i++)
s [i] =getchar ( );
if (s [i]==’/n’)
【1】;
s[i]= 【2】
printf(" display the string /n");
while (*p)
putchar (【3】 );
[填空题]请补充main函数,该函数的功能是:从键盘输入一组字符串,以‘*’结束输入,并显示出这个字符串。
例如,输入abcdefghi*,结果显示adcdefghi。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio. h>
#define N 80
main ( )
{
iht i=-l, j=0;
char str IN];
clrscr ( );
printf("/n Input a string /n");
do
{
i++;
scanf(【1】);
}while(【2】);
printf ("/n**display the string** /n");
while (j<i)
{
printf (【3】);
j++;
}
}