六个章鱼小丸子成本:求编程:用指针方法实现。谢谢!!

来源:百度文库 编辑:高校问答 时间:2024/04/29 05:47:52
1、输入三个数,按从小到大的次序输出
2、编写一个程序,输入15个整数存入一维数组,再按照逆序存放后再输出。
3、比较2个字符串是否相等。
谢谢了高手,把2、3题答案给我吧,供我学习,快要考试了。谢谢!!!

1、输入三个数,按从小到大的次序输出
fun( int *a,int *b,int *c)
{int temp;
if(*a>*b) {temp=*a;*a=*b;*b=temp;}
if(*a>*c) {temp=*a;*a=*c;*c=temp;}
if(*b>*c) {temp=*c;*c=*b;*b=temp;}}
2、编写一个程序,输入15个整数存入一维数组,再按照逆序存放后再输出.
main()
{int a[15],i,*p;
for(i=0;i<15;i++)
scanf("%d",&a[i]);
p=&a[14];
for(i=0;i<15;i++)
printf("%d",*p--);
getch();}

3、比较2个字符串是否相等。
# include "string.h"
main()
{char *p1="asdkf",*p2="akdfkaksd";
if(strcmp(p1,p2)==0) printf("相等");
else printf("不相等");}

1.
#include "stdafx.h"
void MySort(int* pData,int Count)
{
int iTemp;
for(int i=1;i<Count;i++) {
for (int j=Count-1;j>=i;j--){
if(pData[j]<pData[j-1]){
iTemp = pData[j-1];
pData[j-1] = pData[j];
pData[j] = iTemp;
}
}/*end for*/
}/*endfor*/
}

void main(){
int n[3];
int i;
for( i=0; i<3; i++) scanf("%d",&n[i]);
MySort(n,3);
for(i=2; i>=0; i--) printf("%d\t",n[i]);
}

2.3.个你自己做.

# include "stdio.h"
void main()

{ int array[14];Count=0;
for(;Count<15;Count++)
scand("d%",&array[Count]);
for(;Count>0;Count--)
printf("%d",array[Count]);
}