【发布时间】:2016-01-24 05:15:50
【问题描述】:
#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();
}
此程序的输出不交换数组元素,
相反,它开始大量产生数字
整个代码都写在这里
已进行所有其他建议的更改
该函数应该接受一个整数数组及其大小作为参数,并显示一个交换了相邻元素的数组。
【问题讨论】:
-
只需删除
[]。这是一种语法。没有大科学。变量称为n,因此您将n传递给函数,而不是n[]。 -
做到了,现在是一个新问题,但无法解释,输出变得古怪
-
@ArjunSukumaran 哦,男孩,叹息!这不是该网站的工作方式。我们不会为您保姆解决您所有的个人问题。请查看help center 在这里可以询问什么以及如何询问。
标签: c++ compiler-errors codeblocks