#include <iostream>
using namespace std;
int main()
{
start:
int a;
cout << "請輸入"<<endl;
cin >> a;
cout << a<<endl;
goto start;
}
start 可改成其他的東西 goto start 的意思是重新執行start以下的程式
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
2014年9月25日 星期四
基本運算
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b;
cin >> a >> b;
cout << a+b<<endl; /*相加*/
cout << a-b<<endl; /*相減*/
cout << a*b<<endl; /*相乘*/
cout << a/b<<endl; /*相除*/
cout << sqrt(a)<<endl; /*根號*/
}
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
#include <cmath>
using namespace std;
int main()
{
int a,b;
cin >> a >> b;
cout << a+b<<endl; /*相加*/
cout << a-b<<endl; /*相減*/
cout << a*b<<endl; /*相乘*/
cout << a/b<<endl; /*相除*/
cout << sqrt(a)<<endl; /*根號*/
}
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
數字大小排列
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b;
cin >> a;
cin >> b;
if(a>=b)
{
cout<< a<< ","<< b<<endl;
}
else
{
cout<< a<< ","<< b<<endl;
}
}
if是條件句如果符合條件則執行if內的程式
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
#include <cmath>
using namespace std;
int main()
{
int a,b;
cin >> a;
cin >> b;
if(a>=b)
{
cout<< a<< ","<< b<<endl;
}
else
{
cout<< a<< ","<< b<<endl;
}
}
if是條件句如果符合條件則執行if內的程式
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
基本輸入,輸出
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a<<endl;
}
int 是data type 資料型態 宣告函數,變數用
cin則是可由鍵盤輸入的變數
endl = end-L (End Line)用於換行
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
using namespace std;
int main()
{
int a;
cin >> a;
cout << a<<endl;
}
int 是data type 資料型態 宣告函數,變數用
cin則是可由鍵盤輸入的變數
endl = end-L (End Line)用於換行
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
顯示文字
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world"<<endl; /*Hello world 可改為其他字*/
return 0;
}
#include是把程式庫導入,導入iostream才可用cout,cin...之類的指令
cout則是把訊息傳到螢幕上顯示
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
using namespace std;
int main()
{
cout << "Hello world"<<endl; /*Hello world 可改為其他字*/
return 0;
}
#include是把程式庫導入,導入iostream才可用cout,cin...之類的指令
cout則是把訊息傳到螢幕上顯示
--------------------------------------------------------------------------------------------------------------------------
我目前只是個大學一年級的資工生,以上有何不對的地方歡迎指教!!
訂閱:
意見 (Atom)