c 编程题库及答案,c语言试题及答案

1,c语言试题及答案第一题#includevoid fun(int a){ if(a<10) cout<<你给多少分?满意的话我帮你做本人QQ:wellfeng6@126.com
2,c语言编程题答案#include &lt;stdio.h&gt;int Fib (int n);//函数声明void main (){ int i,n; printf ("input the n: "); scanf ("%d",&amp;n); printf ("斐波契数列的前%d项为:\n",n);//输入项数 for (i=0;i&lt;=n;i++) printf ("%d ",Fib (i)); printf ("\n");}int Fib (int n){ if (n==0||n==1) return 1; return Fib(n-2)+Fib(n-1);}
3 , c编程题答案#include "iostream"using namespace std;void main() int x[20]; int i; x[0]=0,x[1]=1; for(i=2;i<20;i++) x[i]=x[i-1]+x[i-2]; for(i=19;i>=0;i--) cout<<x[i]<<" ";}斐波那契数列问题#include<stdio.h>void main() int i; long fib[21]; fib[0]=0; fib[1]=1; for(i=2;i<21;i++) fib[i]=fib[i-1]+fib[i-2]; for(i=20;i>0;i--) printf("F=%d==%d\n",i,fib[i]);}【c 编程题库及答案,c语言试题及答案】
4,C语言编程题答案//排序输入参数数组的指针,长度void bubbleSort(char *buff, int n) int t; for(int i=n-1; i>=0; i--)for(int j=0; j<i; j++)if(buff[j] > buff[j+1])t = buff[j];buff[j] = buff[j+1];buff[j+1] = t;}}}}#include<stdio.h>void main() int a,b,c,n=0,num[1000]; for(a=1;a<=5;a++) for(b=1;b<=5;b++) for(c=1;c<=5;c++) if(a!=b&&a!=c&&b!=c) num[n++]=a*100+b*10+c; printf("一共有%d个这样的三位数,它们是:\n",n); for(a=0;a<n;a++) printf("%5d",num[a]); if((a+1)%10==0)printf("\n"); }}#include <stdio.h>#include <malloc.h>#include <string.h>void sort(char *s[]);int main() int i; char *str[3]; printf("请输入三个字符串:\n"); for(i = 0; i < 3; i++)str[i] = (char *)malloc(256*sizeof(char));scanf("%s", str[i]); } // 排序并输出 sort(str); for(i = 0; i < 3; i++)free(str[i]); } return 0;}void sort(char *s[]) char *temp; int i; if (strcmp(s[0], s[1]) > 0)temp = s[0];s[0] = s[1];s[1] = temp; } if (strcmp(s[0], s[2]) > 0)temp = s[0];s[0] = s[2];s[2] = temp; } if (strcmp(s[1], s[2]) > 0)temp = s[1];s[1] = s[2];s[2] = temp; } for(i = 0; i < 3; i++)printf("%s\n", s[i]); }}

    推荐阅读