91学习

陪伴你每一天!

使用指针实现冒泡排序

#include <stdio.h>void order(int *p,int n){ int i,t,j; for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++) if(*(p+j)>*(p+j+1)){ t=*(p+j); *(p+j)=*(p+j+1); *(p+j+1)=t; } printf("排序后的数组:\n"); for(i=0;i<n;i++){ if(i%

将某一个示例为7个的数字求和

#include <stdio.h>void SUM(int *p,int n){ int i,sum=0; for(i=0;i<n;i++) sum=sum+*(p+i); printf("面值的总数是:%d\n",sum);}int main(){ int *pointer,a[7],i; pointer=a; printf("please input :\n"); for(i=0;i<7;i++) scanf("

将输入的数据从大到小排列

#include <stdio.h>void swap(int *p1,int *p2){ int temp; temp=*p1; *p1=*p2; *p2=temp;}void exchange(int *pt1,int *pt2,int *pt3){ if(*pt1<*pt2) swap(pt1,pt2); if(*pt1<*pt3) swap(pt1,pt3); if(*pt2<*pt3) swap(pt2,pt3);}void main(){ int

变量是形式参数交换两个变量的值

#include <stdio.h>void swap(int a,int b){ int tmp; tmp=a; a=b; b=tmp;}void main(){ int x,y; printf("请输入两个数:\n"); scanf("%d",&x); scanf("%d",&y); swap(x,y); printf("x=%d\n",x); printf("y=%d\n&

指针变量做参数交换两个变量值

#include <stdio.h>void swap(int *a,int *b){ int tmp; tmp=*a; *a=*b; *b=tmp;}void main(){ int x,y; int *p_x,*p_y; printf("请输入两个数:\n"); scanf("%d",&x); scanf("%d",&y); p_x=&x; p_y=&y; swap(p_x,p_y); p

用指向指针的指针输出金属元素

#include <stdio.h>int main(){ int i; char **p; char *element[]={ "锂", "铍", "钠", "镁", "铝", "钾", "钙" }; for(i=0;i<7;i++) { p=element+i; printf("%s\n",*p);

输出12个月

#include <stdio.h>void main(){ int i; char *month[]={ "January", "February", "March", "April", "May", "June", "July", "August", "September", &qu

利用指针实现字符串的复制

#include <stdio.h>void main(){ char str1[]="you are beautiful",str2[30],*p1,*p2; p1=str1; p2=str2; while(*p1!='\0'){ *p2=*p1; *p1++; *p2++; } *p2='\0'; printf("now the str2 is:\n"); puts(str2);}

字符串与指针

#include <stdio.h>int main(){ char *string="hello"; printf("%s",string); printf("\n"); return 0;}

对于一个3行3列数组输出第二行

#include <stdio.h>int main(){ int a[3][3],i,j; printf("please intput :\n"); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d",*(a+i)+j); printf("the second line is:\n"); for(j=0;j<3;j++) printf("%5d