C 语言实例 - 使用引用循环替换数值
C 语言教程
· 2019-02-21 08:13:03
a、b、c 三个变量,通过引用按顺序循环替换他们的值。
实例
#include<stdio.h>
void cyclicSwap(int *a,int *b,int *c);
int main()
{
int a, b, c;
printf("输入 a, b 和 c 的值: ");
scanf("%d %d %d",&a,&b,&c);
printf("交换前:\n");
printf("a = %d \nb = %d \nc = %d\n",a,b,c);
cyclicSwap(&a, &b, &c);
printf("交换后:\n");
printf("a = %d \nb = %d \nc = %d",a, b, c);
return 0;
}
void cyclicSwap(int *a,int *b,int *c)
{
int temp;
// 交换
temp = *b;
*b = *a;
*a = *c;
*c = temp;
}
输出结果为:
输入 a, b 和 c 的值: 1 2 3 交换前: a = 1 b = 2 c = 3 交换后: a = 3 b = 1 c = 2
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Thirty-three Miniatures
Jiří Matoušek / American Mathematical Socity / 2010-6-18 / USD 24.60
This volume contains a collection of clever mathematical applications of linear algebra, mainly in combinatorics, geometry, and algorithms. Each chapter covers a single main result with motivation and......一起来看看 《Thirty-three Miniatures》 这本书的介绍吧!