为了账号安全,请及时绑定邮箱和手机立即绑定

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

https://img1.sycdn.imooc.com//5b41ca22000133bb10801920.jpg

https://img1.sycdn.imooc.com//5b41ca240001122510801920.jpg

https://img1.sycdn.imooc.com//5b41ca2700019eaf10801920.jpg

https://img1.sycdn.imooc.com//5b41ca2800017f2d10801920.jpg

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


正在回答

4 回答

实验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;
}

2 回复 有任何疑惑可以回复我~

实验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;
}


0 回复 有任何疑惑可以回复我~

实验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;
}

0 回复 有任何疑惑可以回复我~

也许你已经考完了,我还是用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的,改改数字就行了

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C语言入门
  • 参与学习       927001    人
  • 解答问题       21533    个

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

进入课程

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

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号