#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 :(得分:0)
电话
swapper(n[],s);
不对。假设swapper
的第一个参数是int*
,则需要:
swapper(n,s);
答案 1 :(得分:0)
删除交换器功能中的[]
。