河北青少年软件编...吧 关注:19贴子:192
  • 20回复贴,共1

10月2日大班C++作业区

只看楼主收藏回复

——————————————————————————
9月22日作业成绩单:
A:张继发、仟润、庞浩正。
B:石洺赫、杨烨硕、陈嘉昊
备足:还有一名同学没有留下姓名(贴吧用户_6S5DAZaye)。
说明:其他同学没有按时提交作业,个别同学连续多次没有提交作业了,除去插班生,其他同学必须按照要求提交作业,如果连这点作业都用心去做,那长大了你又能做什么呢?老师不要求题海战术,但是最基本的课堂练习作业还是要做的。
——————————————————————————
C++大班10月2日作业, 课本page 154 ,(2)题、(4)题、(5)题。
将代码粘贴在回复区域,记得写上自己的name。
如果有运行结果,最好截屏一起附上,大家一起努力!!


IP属地:河北1楼2019-10-07 19:10回复
    #include<iostream>
    #include<math.h>
    using namespace std;
    int a(long x);
    int main ()
    {
    long x;
    cout<<"100内的所有素数是"<<endl;
    for(x=2;x<=100;x++)
    {
    if(a(x)==1)
    cout<<x<<endl;
    }
    }
    int a(long x)
    {
    int i;
    for(i=2;i<=sqrt(x);i++)
    {
    if(x%i==0)
    {
    return 0;
    }
    }
    return 1;
    }
    求素数


    2楼2019-10-10 21:35
    回复
      Very good!还可以再优化


      IP属地:河北来自Android客户端3楼2019-10-11 11:53
      回复
        #include<iostream>
        #include<math.h>
        using namespace std;
        int a(long x);
        int main ()
        {
        long x;
        cout<<"100内的所有质数是"<<endl;
        for(x=2;x<=100;x++)
        {
        if(a(x)==1)
        cout<<x<<endl;
        }
        }
        int a(long x)
        {
        int i;
        for(i=2;i<=sqrt(x);i++)
        {
        if(x%i==0)
        {
        return 0;
        }
        }
        return 0;
        }
        石洺赫


        IP属地:河北4楼2019-10-11 13:04
        回复
          子函数调用时会出问题,你怎么知道他会=0或1,看看你的子函数最后一句,返回的是啥?领悟一下


          IP属地:河北来自Android客户端5楼2019-10-11 17:56
          回复
            #include<iostream>
            #include<math.h>
            using namespace std;
            int a(long x);
            int main ()
            {
            long x;
            cout<<"100内的所有素数是"<<endl;
            for(x=2;x<=100;x++)
            {
            if(a(x)==1)
            cout<<x<<endl;
            }
            }
            int a(long x)
            {
            int i;
            for(i=2;i<=sqrt(x);i++)
            {
            if(x%i==0)
            {
            return 0;
            }
            }
            秦绍语求质数


            来自Android客户端6楼2019-10-11 19:14
            收起回复
              #include<iostream>
              #include<math.h>
              using namespace std;
              int a(long x);
              int main ()
              {
              long x;
              cout<<"100内的所有质数是"<<endl;
              for(x=2;x<=100;x++)
              {
              if(a(x)==1)
              cout<<x<<endl;
              }
              }
              int a(long x)
              {
              int i;
              for(i=2;i<=sqrt(x);i++)
              {
              if(x%i==0)
              {
              return 0;
              }
              }
              王楚煊求质数


              来自Android客户端7楼2019-10-11 22:29
              收起回复
                #include<iostream>
                using namespace std;
                {
                void randbrd
                st
                int temp
                srand(time(NULL))
                tempfor(i=0;i<n;i++)
                if(index!=i)
                temp=a[i]
                return 0;
                }
                石洺赫


                IP属地:河北8楼2019-10-12 19:40
                回复
                  #include<iostream>
                  #include<math.h>
                  using namespace std;
                  int a(long x);
                  int main ()
                  {
                  long x;
                  cout<<"100内的所有质数是"<<endl;
                  for(x=2;x<=100;x++)
                  {
                  if(a(x)==1)
                  cout<<x<<endl;
                  }
                  }
                  int a(long x)
                  {
                  int i;
                  for(i=2;i<=sqrt(x);i++)
                  {
                  if(x%i==0)
                  {
                  return 0;
                  }
                  }
                  return 1;
                  }
                  杨烨硕


                  9楼2019-10-12 20:11
                  收起回复
                    #include<iostream>
                    using namespace std;
                    {
                    void randbrd
                    st
                    int temp
                    srand(time(NULL))
                    tempfor(i=0;i<n;i++)
                    if(index!=i)
                    temp=a[i]
                    return 0;
                    }


                    10楼2019-10-12 20:26
                    收起回复
                      #include <iostream>
                      using namespace std;
                      int main()
                      {
                      int q,w,e;
                      cin>>e;
                      for(q=0;q<e;q++)
                      {
                      for(w=0;w<e-q;w++)
                      {
                      cout<<" ";
                      }
                      for(w=0;w<2*q+1;w++)
                      {
                      cout<<"* ";
                      }
                      cout<<endl;
                      }
                      return 0;
                      }


                      11楼2019-10-13 20:17
                      收起回复
                        #include <iostream>
                        using namespace std;
                        int main()
                        {
                        float x ,y;
                        cin<<n;
                        cin<<x<<y;
                        if(x<60)
                        cout<<ans;
                        }
                        return 0;


                        12楼2019-10-20 20:14
                        回复
                          C++一级考级题库编程题练习
                          第五题
                          ————————————————————————————————————————
                          #include<iostream>
                          using namespace std;
                          int main()
                          {
                          int a;
                          while(1)
                          {
                          cout<<"请输入一个数字"<<endl;
                          cin>>a;
                          if(a%3==0)cout<<"3 ";
                          if(a%5==0)cout<<"5 ";
                          if(a%7==0)cout<<"7 ";
                          if(a%3!=0&&a%5!=0&&a%7!=0)cout<<"n"<<endl;
                          }
                          }
                          ————————————————————————————————————————


                          13楼2019-10-26 20:37
                          回复
                            C++一级考级题库编程题练习
                            第五题
                            ————————————————————————————————————————
                            #include<iostream>
                            using namespace std;
                            int main()
                            {
                            float a,b,c;
                            cout<<"请输入距离"<<endl;
                            cin>>a;
                            b+=50;
                            a/=3.0;
                            a*=3.0;
                            a/=1.2;
                            b+=a;
                            if(b>c)cout<<"Bike"<<endl;
                            if(b<c)cout<<"Walk"<<endl;
                            if(b==c)cout<<"All"<<endl;
                            }
                            ————————————————————————————————————————


                            14楼2019-10-26 20:37
                            回复