1、.1 求最大公约数和最小公倍数(15 分)#include int fun1( int m, int n) /辗转相除法求 m/n的公约数int r;while (n)r=m % n;m=n;n=r;return m; int fun2(int m,int n) /最小公倍数 return m*n/fun1(m,n);int main() int a,b;scanf(“%d,%d“, /输入 printf(“最大公约数:%dn 最小公倍数:%dn“,fun1(a,b),fun2(a,b);return 0;2 排序并插入(15 分)#include void InsertionSort(int
2、* arr, int n) / 插入排序int *last = 0, *next = 0, key = 0, i = 0;for (i = 1; i int fun1( int m, int n) /辗转相除法求 m/n的公约数int r;while (n)r=m % n;m=n;n=r;return m; int main() int a,b;scanf(“%d,%d“, /输入 printf(“%dn“,fun1(a,b);return 0;4.奇数球和.#includeint main() int n; int sum(int n); scanf(“%d“, printf(“%dn“,s
3、um(n);int sum(int n) int b; if(n1) b=sum(n-1)+2*n-1;if(n=1)b=1; return b;5.巧算自然数#includeint step = 1;void fc(int n)/输出 n这个数并按角谷猜想对 n做处理以便进入下一步。返回值是总步数。 if(n = 1)printf(“%d“,n);return; else if(n%2 = 0)printf(“%d,“,n);fc(n/2);step+;elseprintf(“%d,“,n);fc(n*3+1);step+;int main(int argc, char* argv).int
4、 n;scanf(“%d“,fc(n);printf(“nstep=%dn“,step);return 0;6.卖鸭子#include int main()static int i,x8;x7=2;for(i=7;i=0;i-)xi-1=(xi+1)*2;printf(“sum=%dn“,x0);for(i=0;i#include main(). char a100;int i,j;gets(a);i=0;j=strlen(a)-1;while(i=j) printf(“YESn“);else printf(“NOn“);指针排序#include void sort(int *p,int n)
5、; void sort(int *p,int n) int i,j; int temp=0; for(i=0;ipj+1) temp=pj; pj=pj+1; pj+1=temp; int main() int i; int a10; for(i=0;i void find(int *p,int element,int n); void find(int *p,int element,int n) int i,flag=0; for(i=0;iint main()int grade34,i,j,(*p)4=grade,n;float ave=0;for(i=0;i void average(i
6、nt p6,int n); void average(int p6,int n) int i; for(i=0;imax2 printf(“%d,%d,%d,%dn“,p10,p11,p12,p13); printf(“%d,%d,%d,%dn“,p20,p21,p22,p23); else printf(“%d,%d,%d,%dn“,p00,p01,p02,p03); printf(“%d,%d,%d,%dn“,p20,p21,p22,p23); printf(“%d,%d,%d,%dn“,p10,p11,p12,p13); else if(max2max1 printf(“%d,%d,%d
7、,%dn“,p00,p01,p02,p03); printf(“%d,%d,%d,%dn“,p20,p21,p22,p23); else printf(“%d,%d,%d,%dn“,p10,p11,p12,p13); printf(“%d,%d,%d,%dn“,p20,p21,p22,p23); printf(“%d,%d,%d,%dn“,p00,p01,p02,p03); else if(max3max1 printf(“%d,%d,%d,%dn“,p00,p01,p02,p03); printf(“%d,%d,%d,%dn“,p10,p11,p12,p13); else . printf(
8、“%d,%d,%d,%dn“,p20,p21,p22,p23); printf(“%d,%d,%d,%dn“,p10,p11,p12,p13); printf(“%d,%d,%d,%dn“,p00,p01,p02,p03); int main() int i,j; int a36=0; for(i=0;i#include int main()char str1100,str2100;int flag=0,counter=0,l1,l2,i,j;gets(str1);gets(str2);l1=strlen(str1);l2=strlen(str2);for(i=0;imain()printf(
9、“wanglei,86.75n“);printf(“lihong,86.50n“);printf(“zhangli,79.50n“);printf(“liuming,83n“);printf(“AVERAGE:84.50,86.75,82.50,82n“);加密#include#includeint l;void gm(char*a);main()char s100=0;gets(s);l=strlen(s);gm(s);void gm(char*a)int i;char d100=0;for(i=0;i#include typedef struct Char_ char ch;char in
10、tch; struct Char_ *next;CHAR_; int main(void) CHAR_ *node = NULL; CHAR_ *ch_ = NULL; CHAR_ *hear = NULL; .char zimu = a; char panduanzimu; char record;for (; zimu != e; zimu+) ch_ = (CHAR_ *)malloc(sizeof(CHAR_);if (ch_ = NULL) exit(0); ch_-ch = zimu; ch_-next = NULL; if (node = NULL) node = ch_; el
11、se node-next = ch_; node = node-next; if (hear = NULL) hear = node; for (zimu -= 2; zimu != (a - 1); zimu-) ch_ = (CHAR_ *)malloc(sizeof(CHAR_);if (ch_ = NULL) exit(0); ch_-ch = zimu; ch_-next = NULL;node-next = ch_; node = node-next; for (node = hear, zimu = 0; node != NULL; node = node-next, zimu+
12、)node-intch = zimu;scanf(“%c“, node = hear; if (panduanzimu = 0 break; node = node-next; else if (panduanzimu = a node = node-next; printf(“%c“, record); else printf(“N“); node = hear; while (node != NULL) hear = node-next; free(node); node = hear; return 0; 链表合并#include#includeint main()static int
13、i,j,m,n;static char q,x100,y100,z100;gets(x);gets(y); strcat(x,y);m=strlen(x);for(j=0;jxj+i)xj=xj+i;xj+i=q;for(i=0;i0;i-)if(isalpha(zi)m=i;break;for(i=0;i#include int main() int i,j,k=0;char a100,b100,c100;gets(a);for(i=0;ai!=n;i+)printf(“%c“,ai);k+;printf(“n“);for(i=k+1;ai!=0i+)printf(“%c“,ai);.k+;
14、if(ai=nai!=0;+i)printf(“%c“,ai);字符串反向#include#include int main ( ) char str80, c;int i, j, n;gets(str);n = strlen(str);for ( i=0, j=n-1; iint main()long long a,b;char op;scanf(“%lld%c%lld“,switch(op)case +:printf(“%lldn“,a+b);break;case -:printf(“%lldn“,a-b);break;case *:printf(“%lldn“,a*b);.break;case /:printf(“%lldn“,a/b);break;case %:printf(“%lldn“,a%b);break;return 0;复杂的四则运算#include #include int main()static char x100;int i;scanf(“%s“,for(i=0;i=0else if(xi-1=-)x0-=(xi-0);else.continue;printf(“%cn“,x0);return 0;