課程
/后端開(kāi)發(fā)
/C
/C語(yǔ)言入門(mén)
求各位大哥看看!急急急!
2018-07-08
源自:C語(yǔ)言入門(mén) 6-7
正在回答
實(shí)驗(yàn)4
#include<iostream>using namespace std;int main(){?float n,i,sum=0;//定義原始數(shù)據(jù)?cout << "請(qǐng)輸入n:";?cin >> n;?if (n < 10)//滿足n>=10的條件??cout << "請(qǐng)輸入不小于10的數(shù)" << endl;?else?{??for (i = 1; i <= n; i++)//計(jì)算過(guò)程???sum +=( i / ((2 * i - 1)*(2 * i + 1)));??cout << "計(jì)算結(jié)果為:";//顯示結(jié)果??cout << sum << endl;?}?system("pause");?return 0;}
實(shí)驗(yàn)3
#include<iostream>using namespace std;void sfun(char s1[],char s2[]){?int i,j;?for (i = 0, j = 0; i <= 99; i++)//通過(guò)ASCII碼判斷數(shù)組元素是否為數(shù)字?{??if (s1[i] >= 48 && s1[i] <= 57)??{???s2[j] = s1[i];???j++;??}?}?cout << "輸出s2數(shù)組為:" << s2 << endl;//輸出s2數(shù)組
}int main(){?static char s1[100], s2[100];?cout << "請(qǐng)輸入s1數(shù)組:";//構(gòu)建s1數(shù)組?cin >> s1;?sfun(s1, s2);?system("pause");?return 0;}
實(shí)驗(yàn)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++)//計(jì)算并記錄輸入的數(shù)的因子?{??if (n%i == 0)??{???arr[j] = i;???j++;??}?}?max = arr[0];//初始化最大值?for (j = 0; j <=? 49,arr[j]!=0; j++)//計(jì)算最大因子?{??if (arr[j] > max)???max = arr[j];?}?return max;//返回最大因子}int main(){?int n;?cout << "請(qǐng)輸入所要計(jì)算最大因子的數(shù):";?cin >> n;?cout << "該數(shù)最大因子為:";?cout << fact(n) << endl;;?system("pause");?return 0;}
也許你已經(jīng)考完了,我還是用C++寫(xiě)了下,祝你考試不掛科
所發(fā)順序按你的圖片順序來(lái),菜雞編的程序,輕噴
#include<iostream>using namespace std;int main(){?int str[5][5];?int i,j,sum=0;?cout << "請(qǐng)輸入數(shù)組內(nèi)容:" << endl;//創(chuàng)建數(shù)組內(nèi)容?for (i = 0; i <= 4; i++)?{??for (j = 0; j <= 4; j++)???cin >> str[i][j];?}?cout << "輸出數(shù)組結(jié)果為:" << endl;//輸出數(shù)組內(nèi)容?for (i = 0; i <= 4; i++)?{??for (j = 0; j <= 4; j++)???cout << str[i][j] << " ";??cout << endl;?}?for (i = 1; i <= 4; i++)//計(jì)算數(shù)組偶數(shù)行元素和?{??if (i % 2 == 1)??{???for (j = 0; j <= 4; j++)????sum += str[i][j];??}?}?cout << "所有偶數(shù)行元素和為:" << sum << endl;?system("pause");//為了能夠查看程序運(yùn)行結(jié)果所加的語(yǔ)句,可忽略?return 0;}
這個(gè)程序?yàn)榱朔奖銠z查運(yùn)行就沒(méi)用10×10的數(shù)組,用了5×5的,改改數(shù)字就行了
舉報(bào)
C語(yǔ)言入門(mén)視頻教程,帶你進(jìn)入編程世界的必修課-C語(yǔ)言
1 回答哪個(gè)大佬解答一下啊 急急急急急急
1 回答求解答急急急
2 回答急急急!求解答!
4 回答急急急求大神
1 回答急急急急急急求
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-07-18
實(shí)驗(yàn)4
#include<iostream>
using namespace std;
int main()
{
?float n,i,sum=0;//定義原始數(shù)據(jù)
?cout << "請(qǐng)輸入n:";
?cin >> n;
?if (n < 10)//滿足n>=10的條件
??cout << "請(qǐng)輸入不小于10的數(shù)" << endl;
?else
?{
??for (i = 1; i <= n; i++)//計(jì)算過(guò)程
???sum +=( i / ((2 * i - 1)*(2 * i + 1)));
??cout << "計(jì)算結(jié)果為:";//顯示結(jié)果
??cout << sum << endl;
?}
?system("pause");
?return 0;
}
2018-07-18
實(shí)驗(yàn)3
#include<iostream>
using namespace std;
void sfun(char s1[],char s2[])
{
?int i,j;
?for (i = 0, j = 0; i <= 99; i++)//通過(guò)ASCII碼判斷數(shù)組元素是否為數(shù)字
?{
??if (s1[i] >= 48 && s1[i] <= 57)
??{
???s2[j] = s1[i];
???j++;
??}
?}
?cout << "輸出s2數(shù)組為:" << s2 << endl;//輸出s2數(shù)組
}
int main()
{
?static char s1[100], s2[100];
?cout << "請(qǐng)輸入s1數(shù)組:";//構(gòu)建s1數(shù)組
?cin >> s1;
?sfun(s1, s2);
?system("pause");
?return 0;
}
2018-07-18
實(shí)驗(yàn)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++)//計(jì)算并記錄輸入的數(shù)的因子
?{
??if (n%i == 0)
??{
???arr[j] = i;
???j++;
??}
?}
?max = arr[0];//初始化最大值
?for (j = 0; j <=? 49,arr[j]!=0; j++)//計(jì)算最大因子
?{
??if (arr[j] > max)
???max = arr[j];
?}
?return max;//返回最大因子
}
int main()
{
?int n;
?cout << "請(qǐng)輸入所要計(jì)算最大因子的數(shù):";
?cin >> n;
?cout << "該數(shù)最大因子為:";
?cout << fact(n) << endl;;
?system("pause");
?return 0;
}
2018-07-18
也許你已經(jīng)考完了,我還是用C++寫(xiě)了下,祝你考試不掛科
所發(fā)順序按你的圖片順序來(lái),菜雞編的程序,輕噴
#include<iostream>
using namespace std;
int main()
{
?int str[5][5];
?int i,j,sum=0;
?cout << "請(qǐng)輸入數(shù)組內(nèi)容:" << endl;//創(chuàng)建數(shù)組內(nèi)容
?for (i = 0; i <= 4; i++)
?{
??for (j = 0; j <= 4; j++)
???cin >> str[i][j];
?}
?cout << "輸出數(shù)組結(jié)果為:" << endl;//輸出數(shù)組內(nèi)容
?for (i = 0; i <= 4; i++)
?{
??for (j = 0; j <= 4; j++)
???cout << str[i][j] << " ";
??cout << endl;
?}
?for (i = 1; i <= 4; i++)//計(jì)算數(shù)組偶數(shù)行元素和
?{
??if (i % 2 == 1)
??{
???for (j = 0; j <= 4; j++)
????sum += str[i][j];
??}
?}
?cout << "所有偶數(shù)行元素和為:" << sum << endl;
?system("pause");//為了能夠查看程序運(yùn)行結(jié)果所加的語(yǔ)句,可忽略
?return 0;
}
這個(gè)程序?yàn)榱朔奖銠z查運(yùn)行就沒(méi)用10×10的數(shù)組,用了5×5的,改改數(shù)字就行了