一問題代碼:
/* * 文件名稱: * 作 者: 汪榮建* 完成日期: 2017 年 3 月 5日 * 版 本 號:v1.0 * 對任務及求解方法的描述部分:* 輸入描述: 略 * 問題描述: 略* 程序輸出: 略* 問題分析:略 * 算法設計: */
#include<iostream>#include<cmath>using namespace std;int main(){ double x,y; cout<<"請輸入x的值"; cin>>x; if(x<2) cout<<"y="<<x; if(x>=2&&x<6) cout<<"y="<<x*x+1; if(x>=6&&x<10) cout<<"y="<<sqrt(x+1); if(x>=10) cout<<"y="<<1/(x+1);}
運行結果:
第二題代碼:
#include<iostream>using namespace std;int main( ){int i,j,m=5;char str[11][6]; for(i=1;i<=10;i++)if(i%2==0)for(j=0;j<6;j++)str[i-1][j]=' ';else {for(j=0;j<=5;j++){ if(j==m)str[i-1][j]='*'; else str[i-1][j]=' ';}m--;}for(j=0;j<6;j++)str[10][j]='*';for(i=0;i<11;i++){for(j=0;j<6;j++)cout<<str[i][j];for(j=4;j>=0;j--)cout<<str[i][j];cout<<endl;}}
運行結果:
二:心得體會:在編程的時候要先在紙上打下草稿,然后在把代碼打上去。還有就是循環結構比較難,要多實踐,多敲代碼才能更好的掌握。
三:知識點總結:
for循環,while循環,if語句,都要努力的掌握
新聞熱點
疑難解答
圖片精選