题目一前N项和问题
.下列给定程序中函数fun的功能是:求出如下分数序列的前n项之和。和值通过函数值返回。
例如,若n5,则应输出8.391667
请改正程序中的错误,使其得出正确的结果。
#include <stdio.h>
/************found************/
void fun (  int  n )
{  int  a, b, c, k;  double  s;
    s = 0.0;  a = 2;  b = 1;
    for ( k = 1; k <= n; k++ ) {
/************found************/
      s = s + (Double)a / b;
      c = a;  a = a + b; b = c;
    }
    return s;
}
main( )
{  int  n = 5;
printf( "\nThe value of  function is: %lf\n",  fun (  n ) );
(1)double fun(int n)
(2)s=s+(double)a/b;
题目二SS字符串问题
2.下列给定程序中函数fun的功能是:统计substr所指的子符串在str所指的字符串中出现的次数。
例如,若字符串为aaas 1kaaas,子字符串为as,则应输出2
请改正程序中的错误,使它能得出正确的结果。
#include <stdio.h>
int fun (char *str,char *substr)
{  int i,j,k,num=0;
/************found************/
  for(i = 0, str[i], i++)
    for(j=i,k=0;substr[k]==str[j];k++,j++)
/************found************/
      If(substr[k+1]=='\0')
      {  num++;
          break;
      }
  return num;
}
main()
{
  char str[80],substr[80];
  printf("Input a string:") ;
  gets(str);
  printf("Input a substring:") ;
  gets(substr);
  printf("%d\n",fun(str,substr));
(1)for(i=0;str[i];i++)
(2)if(substr[k+1]== '\0')
题目三 变量互换问题1
2. 下列给定程序中函数fun的功能是:实现两个变量值的交换,规定不允许增加语句和表达式。
例如,变量a中的值原为8b中的值原为3,程序运行后a中的值为3c编程必背100题b中的值为8
请改正程序中的错误,使它得出正确的结果。
  #include <stdio.h>
int fun(int *x,int y)
{
  int t ;
/**************found**************/
  t = x ; x = y ;
/**************found**************/
  return(y) ;
}
main()
{
  int a = 3, b = 8 ;
  printf("%d  %d\n", a, b) ;
  b = fun(&a, b) ;
  printf("%d  %d\n", a, b) ;
(1)t = *x ; *x = y ;
(2)return(t) ;return t;
题目三 变量互换问题2
1.下列给定程序中,函数fun的功能是:实现两个整数的交换。例如,给ab分别输入6065,输出为:a65 b60
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
/*************found**************/
void fun(int a,b)
{ int t;
/*************found**************/
  t=b;b=a;a=t;
}
void main()
{int a,b;
  system("CLS");
  printf("Enter a, b: "); scanf("%d%d",&a,&b);
  fun(&a, &b);
  printf("a=%d  b=%d\n ", a,b);
}
(1)void fun(int *a,int *b)
(2)t=*b; *b=*a; *a=t;
   
题目三 变量互换问题3
2. 下列给定程序中,函数fun的功能是:将主函数中两个变量的值进行交换。例如,若变量a中的值为8b中的值为3,则程序运行后,a中的值为3b中的值为8
#include <stdio.h>
/*************found**************/
void fun(int x,int y)
{ int t;
/*************found**************/
  t=x;x=y;y=t;
}
void main()
{ int a,b;
  a=8;
  b=3;
  fun(&a, &b);
  printf("%d  %d\n ", a,b);
}
(1)void fun(int *x, int *y)
(2)t=*x; *x=*y; *y=t;
题目四 最大公约数问题
2. 下列给定程序中函数fun的功能是:求两个非零正整数的最大公约数,并作为函数值返回。
例如,若num1num2分别为4921,则输出的最大公约数为7;若num1num2分别为2781,则输出的最大公约数为27
#include <stdio.h>
int  fun(int  a,int  b)