用c语言编写一个程序

输入3个整数分别放在a,b,c变量中,设置指针变量p1,p2,p3分别指向这三个变量。设计一个fun函数通过这些指针使a,b,c变量的值顺序交换,即把原来a的值给b,把b的值给c,把c的值给a,最后在main函数中输出交换后的结果。

#include"stdio.h"
int fun(int *p1,int *p2,int *p3)
{
int p;
p=*p3,*p3=*p2,*p2=*p1,*p1=p;
}
main()
{
int a,b,c,*p1,*p2,*p3;
scanf("%d,%d,%d",&a,&b,&c);
p1=&a,p2=&b,p3=&c;
fun(p1,p2,p3);
printf("%d,%d,%d",a,b,c);
getch();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-26
-_-b本回答被网友采纳
第2个回答  2010-11-26
你指针不懂?
这个我可以做出来
不过因为太简单了可能楼上的都做了出来.免得我做无用功,你可以先采纳我.或者等到真的没有人做hi我吧
第3个回答  2010-11-26
void fun(int *p1,int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
这是函数体部分,在主函数中定义指针变量,再传递给形参调用就可以了
第4个回答  2010-11-27
#include <string.h>
#include <memory.h>
#include <stdio.h>
/*要求:用C语言编写一个程序
? 可以读入任何一个文本文件,并计算文件中每一个字符出现的次数与百分比,并将结果写入另一个文件中,输出格式如下:
字符 次数 百分比
A 3 1.25% */

void f1()
{
char filename[100];
int charmap[256],filelen,i;
unsigned char c;
FILE *f;
printf("Input file name:");
scanf("%s",filename);
f=fopen(filename,"rb");
if (f==NULL) return;
for (i=0;i<256;i++) charmap[i]=0; filelen=0;
while(fread(&c,1,1,f))
fclose(f);
printf("Output file name:");
scanf("%s",filename);
f=fopen(filename,"w");
if (f==NULL) return;
for (i=0;i<256;i++)
{
char buf[10];
if (charmap[i]==0) continue;
if (i>=0x20 && i<0x80) sprintf(buf,"%3c",i);
else sprintf(buf,"%02XH",i);
fprintf(f,"%s %6d %5.2f\n",buf,charmap[i],double(charmap[i])/filelen);
}

}
/*? 可以在任意一个文本文件中寻找,是否存在一个用户所输入的字符串。*/

void f2()
{
char filename[100];
char buf[256];
char temp[256];
int buflen,position=0;
FILE *f;

printf("Input file name:");
scanf("%s",filename);
f=fopen(filename,"rb");
if (f==NULL) return;

printf("Input string to be searched:");
scanf("%s",buf); buflen=strlen(buf);
if (buflen!=(int)fread(&temp,1,buflen,f))
while(memcmp(buf,temp,buflen)){
memcpy(temp,temp+1,buflen-1); position++;
if (fread(temp+buflen-1,1,1,f)==0)
}
fclose(f);
if (position==-1) printf("not found.\n");
else printf("At %d\n",position);
}

void main()
{
f1();
f2();
}
我可以帮助你,你先设置我最佳答案后,我百度Hii教你。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网