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

查看所有标签

Boolean Reasoning

Boolean Reasoning

Brown, Frank Markham / 2003-4 / $ 19.15

A systematic treatment of Boolean reasoning, this concise, newly revised edition combines the works of early logicians with recent investigations, including previously unpublished research results. Th......一起来看看 《Boolean Reasoning》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具