#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();
}
该程序的输出不交换数组元素,
相反,它开始大量产生数字
整个代码都写在这里
所有其他建议的更改已进行
该函数应该采用一个整数数组及其大小作为参数,并显示一个交换了其相邻元素的数组。
最佳答案
通话
swapper(n[],s);
是不正确的。假设
swapper
的第一个参数是int*
,则必须为:swapper(n,s);
关于c++ - 输出不是预期的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34972514/