| 
                
                  | codeboy   
         
   
  
 | 分享:        ▲
                    
                      ▼         
 
   3-3題 請編寫一方法distance來計算(x1,y1)與(x2,y2)之間的距離,回傳型態為double(在C#中double的涵義為包括小數點,int則否),可由鍵盤輸入該兩點位置,而印出其結果 dev-c++ 4.9.9.1編譯無誤~      有需要完整專案檔再上傳~複製程式 
/*          ******        傳回值: 正數即開根號值                               */
 /* Q      *                  負數即開根號的值含有複數                        */
 /****   *                   範  例: SQ(12345,5)   return = 6.581096*/
 /*     * *    n               SQ(-12345,5)  return = - 6.581096         */
 /*      *                      對 12345 開 5 次根號 得到 6.581096       */
 /*                              若 -12345 則得到 -6.581096 即 6.581096i*/
/* 計算開根號的副程程式,最多能開到 262 次方 */
#include <cstdlib>
#include <iostream>
using namespace std;
double SQ(double n,int Q)
{
 int M,L,I,q;     double s,s2,sold,w;
 M=0; L=0; w=10.0; s=0.0; I=0;
 if(n<0) { I=1; n=-n; }
 while(1)
 {
  sold=s; s2=s;
  for(q=Q;q>1;q--) s2*=s;
  if( (s2>=(n-0.000001)) && (s2<=(n+0.000001)) ) break;
  if(s2>n) { s=sold; M=1; if(L==0) s-=w; }
  else     { L=1;    if(M==0) s+=w;      }
  if(M==1 && L==1)   { M=0; L=0; w/=10; s=s+w*5; }
 }
if(I==1) return(-s);
else     return(s);
}
int main(int argc, char *argv[])
{
    int Q=2;
    double x,x1,x2,y1,y2;
    
    cout<<"請輸入第一個座標的X軸位置:";
    cin>>x1;
    cout<<"請輸入第一個座標的Y軸位置:";
    cin>>y1;
    cout<<"請輸入第二個個座標的X軸位置:";
    cin>>x2;
    cout<<"請輸入第二個座標的Y軸位置:";
    cin>>y2;
    x=((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
    cout<<"兩點距離為:"<<SQ(x,Q)<<endl;
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
 
 |  
                  | 
                
                  | 
 連結有問題請來信,我會盡快修正~^^
 通報時請附上是"哪一篇失效"...這樣我才能去修正~麻煩各位好心人士了~
 [連結失效通報][ 網頁.伺服.程式 討論區]----------------------在世界中心呼喊愛情----------------------
 深深思念一個人的時候,我們不知不覺的地活在世界的中心... |  
                  |  x0  [2 樓]
                    
                    
                     From:未知地址 |  Posted:2005-01-07 12:34 | |  |  
                
                  | codeboy   
         
   
  
 | 分享:        ▲
                    
                      ▼         
 
   4-3 請編寫依程式,印出 int a[10]={45,23,18,10,6,8,67,98,30,50} 內的數值 喝茶沒蛋糕怎可以...快去買~   複製程式 
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
    int a[10]={45,23,18,10,6,8,67,98,30,50};
    for(int c=0;c<10;c++)
    {
       cout<<"a["<<c<<"]="<<a[c]<<endl;       
    }
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
 
 [ 此文章被codeboy在2005-01-07 15:15重新編輯 ] 
 
 |  
                  | 
                
                  | 
 連結有問題請來信,我會盡快修正~^^
 通報時請附上是"哪一篇失效"...這樣我才能去修正~麻煩各位好心人士了~
 [連結失效通報][ 網頁.伺服.程式 討論區]----------------------在世界中心呼喊愛情----------------------
 深深思念一個人的時候,我們不知不覺的地活在世界的中心... |  
                  |  x0  [4 樓]
                    
                    
                     From:未知地址 |  Posted:2005-01-07 15:06 | |  |  
                
                  | codeboy   
         
   
  
 | 分享:        ▲
                    
                      ▼         
 
   4-4題 同上題,計算其總和,並印出來 果然喝茶還是需要點心~   複製程式 
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
    int a[10]={45,23,18,10,6,8,67,98,30,50};
    int sum=0;
    for(int c=0;c<10;c++)
    {
              sum=sum+a[c];
    }
    cout<<"總和為:"<<sum<<endl;
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
 
 |  
                  | 
                
                  | 
 連結有問題請來信,我會盡快修正~^^
 通報時請附上是"哪一篇失效"...這樣我才能去修正~麻煩各位好心人士了~
 [連結失效通報][ 網頁.伺服.程式 討論區]----------------------在世界中心呼喊愛情----------------------
 深深思念一個人的時候,我們不知不覺的地活在世界的中心... |  
                  |  x0  [5 樓]
                    
                    
                     From:未知地址 |  Posted:2005-01-07 15:18 | |  |  
                
                  | codeboy   
         
   
  
 | 分享:        ▲
                    
                      ▼         
 
 4-6題 請編寫一程式,印出 a 三維陣列: int a[3][3]={{32,12,23},{34,68,26},{47,18,59}} 突然覺得..dev-c++真是個好軟體~   複製程式 
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
    int a[3][3]={{32,12,23},{34,68,26},{47,18,59}};
    for(int c=0;c<3;c++)
    {
            for(int d=0;d<3;d++)
            {
                    cout<<"a["<<c+1<<"]["<<d+1<<"]="<<a[c][d]<<endl;
            }
    }
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
 
 |  
                  | 
                
                  | 
 連結有問題請來信,我會盡快修正~^^
 通報時請附上是"哪一篇失效"...這樣我才能去修正~麻煩各位好心人士了~
 [連結失效通報][ 網頁.伺服.程式 討論區]----------------------在世界中心呼喊愛情----------------------
 深深思念一個人的時候,我們不知不覺的地活在世界的中心... |  
                  |  x0  [6 樓]
                    
                    
                     From:未知地址 |  Posted:2005-01-07 15:26 | |  |  
                
                  | option0417 
         
  
 | 分享:        ▲
                    
                      ▼         
 
 4-8、請編寫一程式,計算出三維矩陣相成的結果(c[3][3]=a[3][3]*b[3][3]),並印出來 c矩陣的結果,a與b的結果矩陣內容如下: 公式:Cij=Ai0+B0j+Ai1*B1j+Ai2*B2j               筆誤(Ai0*B0j) int a[3][3]={{1,2,3},{7,8,9},{12,34,11}} int b[3][3]={{7,12,56},{16,18,20},{3,5,18}}複製程式 
#include <iostream>
using namespace std;
int main()
{
    int a[3][3]={{1,2,3},{7,8,9},{12,34,11}};
    int b[3][3]={{7,12,56},{16,18,20},{3,5,18}};
    int c[3][3]={0};
    int i,j,k;
        
    for( i=0 ; i<3 ; i++ )
        for( j=0 ; j<3 ; j++ )
         {
           c[i][j]=0;
           for( k=0 ; k<3 ; k++)
            c[i][j] += a[i][k]*b[k][j];
         }       
             
    
    for( i=0 ; i<3 ; i++ )
     {
        for( j=0 ; j<3 ; j++ )
            cout<<c[i][j]<<" ";
        cout<<endl;    
     }    
            
    system("pause");
    return 0;
}
 
 |  
                  | 
                
                  | 
 |  
                  |  x0  [8 樓]
                    
                    
                     From:台灣中華電信 
 |  Posted:2005-01-07 21:28 | |  |  |