2.程序填空
(1)以下程序的功能是计算1~50之间能被7整除的整数之和。
#include<stdio.h>
void main()
{int i,sum=     0    ;
for(i=1;  50    ;i++)
if(  i%7==0  ) sum+=i;
printf("sum=%d\n",sum);
}
 
(2) 下面程序接收来自键盘的输入,直到输入<Ctrl>+Z(值为-1)键为止。这些字符被原样输出,但若有连续一个以上的空格时只输出一个空格。请填空。
#include <stdio.h>
  void main()
  {char cx;
char front= ;
while (  (cx=getchar())!=\n  )
    {if (cx!= )
putchar(cx);
    if (cx= = )
if (front!= )
        putchar(cx);
          front=cx; 
  }
}
 
3c编程必背100题.程序改错
(1)下列程序的功能是求1+3+5+99的和。
#include <stdio.h>
void main( )
{ int s,i;   //int s=0,i;
  i=1;
  while(i<=99) s=s+i;   //{s=s+i;i++;}
  printf("1+3+5+99的和是:%d\n",s);
  }
(2)下面程序的功能是输入一个正整数,判断是否是素数,若
为素数输出1,否则输出0
 
 
 
 
 
#include <stdio.h>
void main()
{ int i,x,y=0;   //y=1
  scanf("%d",&x);
  for(i=2;i<=x/2&&y;i++)
      if ((x%i)!=0) y=0;   //x%i==0
  printf("%d\n",y);
}
 
4.设计性实验
 
 
(1)
 
/* 方法(1)精度控制  */
#include <stdio.h>
#include <math.h>
main()
{    int s;
    float n,t,pi;
    t=1;  pi=0;  n=1.0;  s=1;
    while((fabs(t))>=1e-6)
    {  pi=pi+t;
  n=n+2;
  s=-s;
  t=s/n;
    }
    pi=pi*4;
    printf("pi=%10.6f\n",pi);
}
/* 方法(2)次数控制*/
#include <stdio.h>
#include <math.h>
main()
{    int s;
    long times;
    float n,t,pi;
    t=1;  pi=0;  n=1.0;  s=1;
    for(times=1;times<=1e9;times++)
    {  pi=pi+t;
  n=n+2;
  s=-s;
  t=s/n;
    }
    pi=pi*4;
    printf("pi=%10.6f\n",pi);
}
 
2)题
 main()
{
  int i,j,frame;
  double wheattal=0;
  double wheatfnu=1;
  printf("Please input frames numbers:");
  scanf("%d",&frame);
  for(i=0;i<frame;i++)
 {
  wheattal+=wheatfnu;
  wheatfnu+=wheatfnu;
 }
  printf("\n Total wheattatols timeter=%e\n",wheattal/1.40e8);
}
3)题
/*方法一:使用递推公式n=n+2*/
 
 
main()
{
  int  i,n=1;
  double s=0,t=1;
  for(i=1;i<=20;i++)
  {
  t*=n;
  s+=t;
  n+=2;
  }
  printf("s=%lf",s);
  getch();
}
 
/*方法二:使用通项公式2*i+1*/
main()
{
  int  i;
  double s=0,t=1;
  for(i=1;i<=20;i++)
  {
  t*=2*i+1;
  s+=t;
  }
  printf("s=%lf",s);
  getch();
}
 
 
 
/*方法三*/
#include "stdio.h"
main()
{
long total,sum,m,n,t;
total=0;
for(m=1;m<=20;m++)
 {
  sum=1;t=1;
  for(n=1;n<=m;n++) { sum=sum*t; t=t+2;}
  total=total+sum;
  }
  printf("total=%ld",total);
}
 
 
 
2.程序填空
(1)以下程序的功能是计算1~50之间能被7整除的整数之和。
#include<stdio.h>
void main()
{int i,sum=     0    ;
for(i=1;  50    ;i++)
if(  i%7==0  ) sum+=i;
printf("sum=%d\n",sum);
}
 
(2) 下面程序接收来自键盘的输入,直到输入<Ctrl>+Z(值为-1)键为止。这些字符被原样输出,但若有连续一个以上的空格时只输出一个空格。请填空。
#include <stdio.h>
  void main()
  {char cx;
char front= ;
while (  (cx=getchar())!=\n  )
    {if (cx!= )
putchar(cx);
    if (cx= = )
if (front!= )