zoukankan      html  css  js  c++  java
  • 第七周作业

    #include<stdio.h>
    int main()
    {
    	int N,i=1,c;
    	float S,n,a,b;
    	S=0;
    	a=1;b=1,c=1;
    	scanf("%d",&N);
    	while(i<=N)
    	{
    	    n=a/b;
    		S=(float)S+n*c;
    		a=a+1.0f;
    		b=b+2.0f;
    		i++;
    		c=c*(-1);
    	}
    	printf("%.3f",S);
    	return 0;
    }
    

      思路是想好分数间的关系,a/b要注意数据类型,还有正负数的问题用c=c*(-1)解决

    #include<stdio.h>
    int main()
    {
      double average,s;
      int count,N,i,g;
      scanf("%d",&N);
    for(i=0,s=0,count=0;i<N;i++)
      {
        scanf("%d",&g);
        if(g>=60)
      	{
    	  count++;
        }
    	s=s+g;
    	average=s/N;
      }
      printf("average = %.1f
    ",average);
      printf("count = %d",count);
      return 0;
     } 
    

      这道题思路先用for语句把循环条件列出来,再用if判断是否合格,再算平均值

    我的乌龟截图

    我的乌龟地址:https://coding.net/u/jinjian155/p/test/git/commit/eb68b6e0a51524fee1585b3c806c0dde96ff4306

    个人总结:这周有学习了很多新知识,进一步的学习了循环,收获良多。我还有很多需要学习的地方,比如设计程序的思路,而且我对数据的运用还不是很熟练,这些需要每天的练习来实现。未来的一周我将会更加的努力的。

    评论地址:http://www.cnblogs.com/kimhae/p/7856811.html

    http://www.cnblogs.com/jhd1127/p/7853312.html

    http://www.cnblogs.com/jz19990201/p/7857799.html

  • 相关阅读:
    CBV进阶(一)
    uva 11748 Rigging Elections
    uva 11573 Ocean Currents(bfs+优先队列)
    无向图的欧拉路
    poj 3254 Corn Fields
    hdu 1114
    hdu 2639 (第k小的01背包)
    uva 1347 tour
    uva 437 The Tower of Babylon
    uva 1025 A Spy in the Metro(动态规划)
  • 原文地址:https://www.cnblogs.com/jinjian155/p/7858506.html
Copyright © 2011-2022 走看看