課程
/后端開發
/C
/C語言入門
求各位大哥看看!急急急!
2018-07-08
源自:C語言入門 6-7
正在回答
實驗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;}
實驗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;}
實驗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;}
也許你已經考完了,我還是用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語言
1 回答哪個大佬解答一下啊 急急急急急急
2 回答急急急!求解答!
1 回答求解答急急急
4 回答急急急求大神
2 回答請求大神來教我這題選什么,明天考試啦急急急
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-07-18
實驗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
實驗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
實驗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
也許你已經考完了,我還是用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的,改改數字就行了