返回列表 發帖

【課堂練習】計算 2 的 16 次方

試利用 for 迴圈, 計算 2 的 16 次方 的值.



本帖隱藏的內容需要回復才可以瀏覽

  1. #include<iostream>
  2. using namespace std;
  3.     int main()
  4.     {
  5.         int res=1;

  6.         for(int i=1;i<=16;i++)
  7.         {
  8.             res*=2;
  9.         }
  10.         cout<<res<<endl;
  11.     }
複製代碼

TOP

回復 1# 陳育霖

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {     int n=1;
  6.       for(int i=1;i<=16;i++)
  7.       {
  8.           n=n*2;
  9.       }      
  10.       cout<<"2的16次方為: "<<n;
  11.       system("pause");
  12.       return 0;
  13. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1;
  7.     for(int i=0; i<16; i=i+1)
  8.     n=n*2;
  9.     cout<<n<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
  13.    
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=1;
  7.     for(int i=0;i<16;i++)
  8.     {
  9.     a=a*2;        
  10.     }cout<<"2的16次方為: "<<a<<endl;
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1;
  7.     for(int i=0;i<16;i++)
  8.     {
  9.         n=n*2;
  10.     }
  11.     cout<<"2 的16 次方為: "<<n<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int k=1;
  7.     for(int i=0; i<16; i++)
  8.        k=k*2;
  9.     cout<<"2 的16 次方為: "<<k<<endl;
  10.    
  11.     system("pause");
  12.     return 0;
  13.    
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1;
  7.     for(int i=0;i<16;i++)
  8.     {
  9.         n=n*2;
  10.     }
  11.     cout<<"2的16次方為: "<<n<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=1;
  7.     for(int i=0;i<16;i++)
  8.         a=a*2;
  9.     cout<<"2 的 16 次方為: "<<a<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     int n = 1;
  6.     for(int i = 0; i < 16; i++){
  7.         n = n * 2;
  8.     }
  9.     cout << "2的16次方為:" << n << endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         int u=1;
  7.         for(int i=16;i>0;i--)
  8.         {
  9.                 u=u*2;
  10.         }
  11.         cout<<"2 to the 16th power is "<<u<<"\n";
  12.         system("pause");
  13.         return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=1;
  7.     for(int b=1;b<=16;b++)
  8.         a=a*2;
  9.     cout<<"2 的16 次方為: "<<a<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

TOP

返回列表