一道很简单的编程题reversing numbers

供稿:hz-xin.com     日期:2025-01-15
一个很简单的编程题目~~

指针实现:
#include
#include
#define N 50
void main()
{char str1[N],str2[N],*p1=str1,*p2=str2;
printf("Input a string:
");p1=gets(str1);
printf("str1=%s
",p1);
printf("str1 copy into str2.
str2=%s
",strcpy(p2,p1));
printf("str_long=%d
",strlen(p2));
}
数组实现:
#include
#include
#define N 50
void main()
{char str1[N],str2[N];
printf("Input a string:
");gets(str1);
printf("str1=%s
",str1);
printf("str1 copy into str2.
str2=%s
",strcpy(str2,str1));
printf("str_long=%d
",strlen(str2));
}

{
int i,j,a[10],b[10];
for(i=0;i<10;i++)
{cin>>a[i];}

for(i=9;i>=0;i--)//条件应该是>=0
{//这里的那句没用 呵呵~
j=9-i;
b[j]=a[i];
cout<<b[j];}
cout<<endl;}
//这样应该就行了 呵呵~

是c语言的不?
#include<stdio.h>
void main
{
int a[7];
int i;
printf("Please enter your 7 digit student number: ");
for(i=0;i++;i<7)
scanf("%d",&a[i]);
prinrf("That number reversed is :");
for(i=6;i--;i>=0)
printf("%d",a[i]);
}

#include"stdio.h"
int main()
{
int i,N;
printf("Please enter your 7 digit student number: ");
scanf("%d",&N);
printf("That number reversed is : ");
for(i=0;i<7;i++)
{
printf("%d",N%10);
N = N/10 ;
}
printf("\n");
return 0;
}

#include"stdio.h"
int main()
{
int i,N;
printf("Please enter your 7 digit student number: ");
scanf("%d",&N);
printf("That number reversed is : ");
for(i=0;i<7;i++)
{
printf("%d",N%10);
N = N/10 ;
}
printf("\n");
return 0;
}
给分