2016-01-24 81 views
-4
#include<iostream> 
#include<conio.h> 
#include<string.h> 
#include<ctype.h> 
#include<stdio.h> 


using namespace std; 



int swapper(int n[],int s 
) 
{ 
for(int i=0;i<s;i++) 
{ 
    int temp=n[i]; 
    n[i]=n[i+1]; 
    n[i+1]=temp; 
} 
cout<<"\n Array Swapped !!!"; 
for (int i=0;1<s;i++) 
{ 

    cout<<n[i]<<"\t"; 
} 
return 0; 
    } 


int main() 

{ 
int n[20]; int s; 

cout<<"\n enter array size:"; 

cin>>s; 
cout<<"enter no in array according to size given"; 

for(int j=0;j<s;j++) 

    { 

     cin>>n[j]; 

    } 

swapper(n,s); 

return 0; 

getch(); 

} 

輸出到這個程序不交換數組元素,
而是開始在大量
整個代碼寫在這裏
其他所有建議已經作了修改輸出是不是有什麼期望

生產編號

該函數應該將一個整數數組及其大小作爲參數,並顯示一個數組及其相鄰元素進行交換。

+0

只要刪除'[]'。這是一種語法。沒有大科學。變量被稱爲'n',所以你將'n'傳遞給函數,而不是'n []'。 – Drop

+1

做到了這一點,現在一個新的問題,但無法解釋,輸出會變得古怪 –

+0

@ArjunSukumaran哦,男孩,嘆!這不是網站的工作方式。我們不會幫你解決你所有的個人問題。請查看[幫助中心](http://stackoverflow.com/help/asking)您可以在此處詢問的內容和方式。 –

回答

0

呼叫

swapper(n[],s); 

是不對的。假設swapper的第一個參數是int*,它需要:

swapper(n,s); 
0

在交換技術功能刪除[]