c语言编程:将一个数组中的值按逆序重新存放,例如,原来顺序为8,6,5,4,3,要求改为3,4,5
c语言编程:将一个数组中的值按逆序重新存放,例如,原来顺序为8,6,5,4,3,要求改为3,4,5,6,8。...
c语言编程:将一个数组中的值按逆序重新存放,例如,原来顺序为8,6,5,4,3,要求改为3,4,5,6,8。
展开
展开全部
#include<iostream>
using namespace std;
int main()
{
int a[100],b[100][100],c[100][100],N,m,i,t=0,t1=0,s,j,l,o,k;
cin>>N;
for (i=1;i<=N;i++)
{
cin>>a[i];
for (j=1;j<=a[i];j++)
c[i][j]=1;
for (j=1;j<=a[i];j++)
cin>>b[i][j];
for (j=1;j<=a[i];j++)
{
s=b[i][j];
while (s!=0)
{
o=s%10;
s=s/10;
c[i][j]=c[i][j]*10+o;
}
}
for (j=1;j<=a[i]-1;j++)
{
for (k=1;k<=a[i]-j;k++)
if (c[i][k]>c[i][k+1])
{
t=c[i][k];
c[i][k]=c[i][k+1];
c[i][k+1]=t;
t1=b[i][k];
b[i][k]=b[i][k+1];
b[i][k+1]=t1;
}
}
}
for (i=1;i<=N;i++)
{
for (j=1;j<=a[i];j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
using namespace std;
int main()
{
int a[100],b[100][100],c[100][100],N,m,i,t=0,t1=0,s,j,l,o,k;
cin>>N;
for (i=1;i<=N;i++)
{
cin>>a[i];
for (j=1;j<=a[i];j++)
c[i][j]=1;
for (j=1;j<=a[i];j++)
cin>>b[i][j];
for (j=1;j<=a[i];j++)
{
s=b[i][j];
while (s!=0)
{
o=s%10;
s=s/10;
c[i][j]=c[i][j]*10+o;
}
}
for (j=1;j<=a[i]-1;j++)
{
for (k=1;k<=a[i]-j;k++)
if (c[i][k]>c[i][k+1])
{
t=c[i][k];
c[i][k]=c[i][k+1];
c[i][k+1]=t;
t1=b[i][k];
b[i][k]=b[i][k+1];
b[i][k+1]=t1;
}
}
}
for (i=1;i<=N;i++)
{
for (j=1;j<=a[i];j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
static void Main(string[] args)
{
Console.WriteLine("输入字符串");
string i = Console.ReadLine();
char iChar = i[1];
string a=null;
foreach (char c in i)
{
a = c + a;
}
Console.WriteLine("输出相反字符串:{0}", a);
Console.ReadKey();
}
{
Console.WriteLine("输入字符串");
string i = Console.ReadLine();
char iChar = i[1];
string a=null;
foreach (char c in i)
{
a = c + a;
}
Console.WriteLine("输出相反字符串:{0}", a);
Console.ReadKey();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void main()
{ int a[5]={ 8,6,5,4,3 },i,j,k;
for ( i=0;i<4;i++ ) for ( j=i+1;j<5;j++ ) if ( a[i]>a[j] ) { k=a[i];a[i]=a[j];a[j]=k; }
for ( i=0;i<5;i++ ) printf("%d ",a[i]); printf("\n");
}
void main()
{ int a[5]={ 8,6,5,4,3 },i,j,k;
for ( i=0;i<4;i++ ) for ( j=i+1;j<5;j++ ) if ( a[i]>a[j] ) { k=a[i];a[i]=a[j];a[j]=k; }
for ( i=0;i<5;i++ ) printf("%d ",a[i]); printf("\n");
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询