急急急!快考试了!求大佬解答!

来源:6-7 字符串与数组

慕少2054140

2018-07-08 16:25

https://img.mukewang.com/5b41ca22000133bb10801920.jpg

https://img1.mukewang.com/5b41ca240001122510801920.jpg

https://img.mukewang.com/5b41ca2700019eaf10801920.jpg

https://img3.mukewang.com/5b41ca2800017f2d10801920.jpg

求各位大哥看看!急急急!


写回答 关注

4回答

  • 枪兵甩毒爆
    2018-07-18 10:20:13

    实验4

    #include<iostream>
    using namespace std;
    int main()
    {
     float n,i,sum=0;//定义原始数据
     cout << "请输入n:";
     cin >> n;
     if (n < 10)//满足n>=10的条件
      cout << "请输入不小于10的数" << endl;
     else
     {
      for (i = 1; i <= n; i++)//计算过程
       sum +=( i / ((2 * i - 1)*(2 * i + 1)));
      cout << "计算结果为:";//显示结果
      cout << sum << endl;
     }
     system("pause");
     return 0;
    }

  • 枪兵甩毒爆
    2018-07-18 10:19:33

    实验3

    #include<iostream>
    using namespace std;
    void sfun(char s1[],char s2[])
    {
     int i,j;
     for (i = 0, j = 0; i <= 99; i++)//通过ASCII码判断数组元素是否为数字
     {
      if (s1[i] >= 48 && s1[i] <= 57)
      {
       s2[j] = s1[i];
       j++;
      }
     }
     cout << "输出s2数组为:" << s2 << endl;//输出s2数组

    }
    int main()
    {
     static char s1[100], s2[100];
     cout << "请输入s1数组:";//构建s1数组
     cin >> s1;
     sfun(s1, s2);
     system("pause");
     return 0;
    }


  • 枪兵甩毒爆
    2018-07-18 10:18:52

    实验2

    #include<iostream>
    using namespace std;
    int fact(int n)
    {
     static int arr[50];
     int i,j,max;
     for (i = 1,j=0; i < n; i++)//计算并记录输入的数的因子
     {
      if (n%i == 0)
      {
       arr[j] = i;
       j++;
      }
     }
     max = arr[0];//初始化最大值
     for (j = 0; j <=  49,arr[j]!=0; j++)//计算最大因子
     {
      if (arr[j] > max)
       max = arr[j];
     }
     return max;//返回最大因子
    }
    int main()
    {
     int n;
     cout << "请输入所要计算最大因子的数:";
     cin >> n;
     cout << "该数最大因子为:";
     cout << fact(n) << endl;;
     system("pause");
     return 0;
    }

  • 枪兵甩毒爆
    2018-07-18 10:17:59

    也许你已经考完了,我还是用C++写了下,祝你考试不挂科

    所发顺序按你的图片顺序来,菜鸡编的程序,轻喷

    #include<iostream>
    using namespace std;
    int main()
    {
     int str[5][5];
     int i,j,sum=0;
     cout << "请输入数组内容:" << endl;//创建数组内容
     for (i = 0; i <= 4; i++)
     {
      for (j = 0; j <= 4; j++)
       cin >> str[i][j];
     }
     cout << "输出数组结果为:" << endl;//输出数组内容
     for (i = 0; i <= 4; i++)
     {
      for (j = 0; j <= 4; j++)
       cout << str[i][j] << " ";
      cout << endl;
     }
     for (i = 1; i <= 4; i++)//计算数组偶数行元素和
     {
      if (i % 2 == 1)
      {
       for (j = 0; j <= 4; j++)
        sum += str[i][j];
      }
     }
     cout << "所有偶数行元素和为:" << sum << endl;
     system("pause");//为了能够查看程序运行结果所加的语句,可忽略
     return 0;
    }

    这个程序为了方便检查运行就没用10×10的数组,用了5×5的,改改数字就行了

C语言入门

C语言入门视频教程,带你进入编程世界的必修课-C语言

926866 学习 · 21068 问题

查看课程

相似问题