指针
来源:互联网 发布:免费数据库系统有哪些 编辑:程序博客网 时间:2024/05/20 20:03
2011-05-15 23:01:42
1.输入三个整数,按由小到大的顺序输出。
程序代码:
#include<stdio.h>
void swap(int *p1,int *p2);
int main(void)
{
int a,b,c;
printf("Please input three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
swap(&a,&b);
if(a>c)
swap(&a,&c);
if(b>c)
swap(&b,&c);
printf("the right sequence is:%d %d %d/n",a,b,c);
}
void swap(int *p1,int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
2.输入3个字符串,按由小到大的顺序输出。
程序代码:
#include<string.h>
#include<stdio.h>
#define N 20
void swap(int *p1,int *p2);
int main(void)
{
char *a[N],*b[N],*c[N];
printf("Please input three charactices:/n");
gets(a);
gets(b);
gets(c);
if(strcmp(a,b)>0)
swap(a,b);
if(strcmp(a,c)>0)
swap(a,c);
if(strcmp(b,c)>0)
swap(b,c);
printf("the right order is:/n%s/n%s/n%s/n",a,b,c);
}
void swap(char *p1,char *p2)
{
char *temp[N];
strcpy(temp,p1);
strcpy(p1,p2);
strcpy(p2,temp);
}
输入函数gets()和scanf均可以实现从键盘输入,但是使用gets()可以避免因字符未填满定义的内存而出现的乱码现象。
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- 指针
- Exception starting filter struts2 java.lang.NullPointerException 解决...
- ZOJ 1115 解题报告
- Bloom Filter概念和原理
- WAV文件格式剖析
- 返回引用需要注意的问题
- 指针
- ASP.NET获取客户端IP地址_系统版本_浏览器版本
- Java程序性能优化之找出内存溢出元凶
- 使Apache(Linux)支持Silverlight
- qt表格
- 数据结构-串的复习
- 设置TOMCAT的内存
- ASP.NET刷新页面的几种方法
- 2011/5/15