一个为了练习使用指针而编的小程序,第一部分是用的起泡法,第二部分是使用指.....
#include<stdio.h>#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<cmath>
int main()
{
void copy(int* p1, int* p2, int* p3);
int a = { 0 }, i = 0, j = 0, temp = 0, k = 0,*pp1,*pp2,*pp3,d,e,f;
printf("please input a num to choice:\n");
scanf_s("%d", &k);
if (1==k)
{
printf("plese input three num:\n");
scanf_s("%d,%d,%d", &a, &a, &a);
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2 - i; j++)
{
if (a > a)
{
temp = a;
a = a;
a = temp;
}
}
}
printf("%d,%d,%d", a, a, a);
}
else
{
printf("ok,l got y|^-^|");
printf("\nplease input three num to cmp:\n");
scanf_s("%d,%d,%d", &d, &e, &f);
pp1 = &d;
pp2 = &e;
pp3 = &f;
copy(pp1, pp2, pp3);
}
printf("%d,%d,%d\n", d, e, f);
system("pause");
return 0;
}
void copy(int* p1, int* p2, int* p3)
{
void exchange(int* p1, int* p2);
if (*p1 < *p2)
{
exchange(p1, p2);
}
if (*p1 < *p3)
{
exchange(p1, p3);
}
if (*p2 < *p3)
{
exchange(p2, p3);
}
}
void exchange(int* p1, int *p2)
{
int temp;
if (*p1 < *p2)
{
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
}
页:
[1]