输入10个整数到数组a,将数组a中的数倒序放入数组b,输出a和b中所有对应元素的和
2个回答
展开全部
#include <iostream.h>
void sort(int a[], int num)
{
for (int i = 0; i < num-1; i++)
{
for (int j = num-1; j > i; j--)
{
if (a[j] > a[j-1])
{
int tmp = a[j-1];
a[j-1] = a[j];
a[j] = tmp;
}
}
}
}
void disply(int y[], int num)
{
for (int x = 0; x < num; x++)
{
cout << y[x] << " ";
}
cout << '\n';
}
void yourway(int s[], int d[], int num)
{
cout << "plesea input: " << endl;
for (int x = 0; x < 10; x++)
{
cin >> s[x];
}
cout <<"finished: "<<endl;
for (int x = 0; x < num; x++)
{
d[x] = s[x];
}
sort(d,10);
cout <<"source: ";
disply(s,10);
cout <<"destination: ";
disply(d,10);
}
int main()
{
int a[10], b[10];
yourway(b,a,10);
return 0;
}
void sort(int a[], int num)
{
for (int i = 0; i < num-1; i++)
{
for (int j = num-1; j > i; j--)
{
if (a[j] > a[j-1])
{
int tmp = a[j-1];
a[j-1] = a[j];
a[j] = tmp;
}
}
}
}
void disply(int y[], int num)
{
for (int x = 0; x < num; x++)
{
cout << y[x] << " ";
}
cout << '\n';
}
void yourway(int s[], int d[], int num)
{
cout << "plesea input: " << endl;
for (int x = 0; x < 10; x++)
{
cin >> s[x];
}
cout <<"finished: "<<endl;
for (int x = 0; x < num; x++)
{
d[x] = s[x];
}
sort(d,10);
cout <<"source: ";
disply(s,10);
cout <<"destination: ";
disply(d,10);
}
int main()
{
int a[10], b[10];
yourway(b,a,10);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询