- 博客(49)
- 收藏
- 关注
原创 第三章第41题 哥德巴赫猜想
#include#includeint prim(int num){ int i = 2,n = 1; int a = sqrt(num); while(i { if(num%i == 0) { n = 0; break; } i++; } return n;}int main(){
2015-06-05 10:59:24 620
原创 第三章第41题 哥德巴赫猜想
#include#includeint prim(int num){int i=2,n=1;int a=sqrt(num);while(iif(num%i == 0){n = 0;break;}i++;}return n;}int main(){int x=4,i;while(1){printf("请输入一个大于四的偶
2015-05-29 17:46:30 638
原创 第三章第45题
#includeint sum(int n){int SUM;if(n==1)SUM = 1;elseSUM = n + sum(n-1);return SUM;}int main(){int x;while(1){printf("请输入x\n");scanf("%d",&x);printf("sum=%d",sum(x));}r
2015-05-28 13:00:44 471
原创 第三章第46题 Fibonacci
#includelong Fibo(int n){long Fibonacci;if ((n==1)||(n==2))Fibonacci = 1;elseFibonacci = Fibo(n-1) + Fibo(n-2);return Fibonacci;}int main(){int a;while(1){printf("请输入a\n");
2015-05-28 12:50:42 396
原创 第三章第42题
#includeint Count(double a[],int n){ int i,b=0; float k,m=0; for(i=0;i m = m + a[i]; k = m/n; for(i=0;i { if(a[i]>=k) b++; } printf("大于平均值的个数为:%d\n",b); return b;}i
2015-05-25 21:23:01 390
原创 第三章第40题 Sn=1+1/1!+1/2!+···+1/n!
#includefloat fun(int n){float Sn=1,a=1,i;for(i=1;i{a = a*i;Sn = Sn + 1/a;}return Sn;}int main(){int b;char ch=0;while(1){printf("请输入b\n");scanf("%d",&b);if(b==0)
2015-05-25 12:41:19 1612
原创 第三章第39题,次方
#includeint fun(int x,int n){int a=1,i;for(i=0;i{a = a*x;}printf("%d",a);return a;}int main(){int k,m;while(1){printf("请输入k,m\n");scanf("%d%d",&k,&m);fun(k,m);}retu
2015-05-23 18:22:03 415
原创 第三章第十九题 逆序
#includeint main(){int i,t,n,a[100];while(1){printf("请输入n\n");scanf("%d",&n);printf("请输入%d个元素\n",n);for(i=0;iscanf("%d",&a[i]);for(i=0;i{t = a[i];a[i] = a[n-1-i];a[n-1-i]
2015-05-20 13:38:31 433
原创 第三章第二十题 转换进制
#include void trans(int n,int base) { int a[10],i=0,k; if(base==2) { while (n != 0) { a[i]= n%2;
2015-05-19 18:17:37 451 1
转载 xxx
#include #include //阅读程序,在读懂程序的基础上运行程序,//观察运行结果,发现其中出现的问题,并解决://修改BubbleSort函数(函数头也可修改),使得//在对成绩排序时,各成绩对应的人名也做相应调整//typedef int INT;//typedef char * PCHAR;typedef char STR[10];typede
2015-05-08 11:57:46 448
原创 第三章第32题约瑟夫环问题
#include int main(){ int i,j,k,m; int a[60]; m=0; k=0; for(i=0;i { a[i]=i+1; } for(j=0;j { if(a[j]!=0) { k++
2015-05-02 18:08:45 523 1
原创 第三章第十八题sum
#includeint powers(int m,int n){int i,sum=1;for(i=1;i{sum = sum*m;}return sum;}int sum_of_powers(int k,int n){int i,sum=0;for(i=1;i{sum = sum + powers(i,k);}return su
2015-05-02 15:23:07 429
原创 年月日输入正确的判断与转换格式,第三章第36题
#includeint printdate(int year,int month,int day){ switch(month){case 1:{if((day>31)||(dayprintf("不合理\n");elseprintf("January %d, %d\n",day,year);}break;case 2:{if((yea
2015-05-01 16:57:34 526
原创 第三章第30题杨辉三角(图)20150427
#include int main(){ int a[12]={0,1},b[12]={0}; int i,j,n=3; printf("%-3d",a[1]); printf("\n"); for(j=0;j { for(i=1;i b[i]=a[i]+a[i-1]; for(i=1;i
2015-04-27 18:00:44 597
原创 第三章第30题杨辉三角20150427
#includeint main(){long double x,y,z,m,k,c,d,t=1,p=1,q=1;printf("请输入第几行第几列"); scanf("%lf %lf",&m,&k); for(x=1;x p = p*x; for(y=1;y q = q*y; for(z=1;z t = t*z;
2015-04-27 17:58:22 502
原创 第三章第二十九题20150425
#include#includeint main (){int i,j,a[10000];srand(5);for(i=0;i{a[i] = (int)(10000*rand()/(RAND_MAX+1.0));}for(i=0;i{if(a[i]>a[i+1]){j = a[i];a[i] = a[i+1];a[i+1] = j;
2015-04-25 14:51:33 399
原创 第三章第二十八题字母大小写转换,数组20150423
#include#includeint main(){int i,n;char a[20];while(1){printf("请输入一串字符:\n");gets(a);n=strlen(a);for(i=0;i{if((a[i]>='a') && (a[i]a[i] = 'A' + a[i] - 'a';else if((a[i]>='A
2015-04-23 18:17:20 530
原创 第三章第二十一题算成绩,,,,20150423
#include int main (){int a[10];int i,max,x=0;float n,m=0;printf("请输入十名同学的成绩:\n");for(i=0;iscanf("%d",&a[i]);for(i=0;im = m + a[i];n = m/10;for(i=0;i{if(a[i]>a[i-1])max =
2015-04-23 17:44:40 410
原创 第三章第十七题20150422
#include int main (){int a[10];int i;float n,m=0;printf("请输入十个数:\n");for(i=0;iscanf("%d",&a[i]);for(i=0;im = m + a[i];n = m/10;printf("平均值为:%f",n);return 0;}
2015-04-22 23:11:01 360
原创 第三章第十六题20150422
#include int add(int a[],int n){int t=0,i,j;float b;for(i=0;it = t + a[i]; b = t/n;j = 0;for(i=0;i{if(a[i]>b)j++;}printf("%d",j);return n;}int main (){int a[20]
2015-04-22 22:09:10 391
原创 第三章第十五题插入数字20150419
#includeint main(){ int a[5]={1,3,5,7}; int i,j,t; int b=a[4]; printf("请输入一个数:"); scanf("%d",&a[4]); for(j=0;j { for(i=0;i { if(a[i]>a[i+1]) { t=a[i]; a[i]=a[
2015-04-19 23:04:30 403
原创 第三章第十四题倒序20150419
#include int Reverse(unsigned int s){int b=0,r;r = s%10;s = s/10;while(s!=0){b = b*10 + r;r = s%10;s = s/10;}b = b*10 + r;printf("%d\n",b);return s;}int main (){uns
2015-04-19 22:26:08 373
原创 第三章第十题三角形面积20150418
#include #include float triangle(int a,int b,int c){int p;float S;if((a+b>c)&&(a+c>b)&&(b+c>a)){printf("该三角形合理\n");p = (a+b+c)/2;S = sqrt(p(p-a)(p-b)(p-c));printf("三角形面积是:%f\n",
2015-04-18 12:27:56 339
原创 第三章第六题20150418
#include char up(char ch){if(ch>='a' && chch = 'A' + ch - 'a';else ch = ch;printf("%c",ch);return ch; }int main (){char ch;while(1){scanf("%c",&ch);up(ch);}return
2015-04-18 10:22:16 370
原创 从小到大排序2
#include#includevoid sort(int a[]);void print();using namespace std;int main(){ int a[10]={9,6,3,8,5,2,7,4,1,0}; int i; for(i=0;iprintf("%-3d",a[i]); printf("\n");sort(a,a+10);
2015-04-17 11:14:57 401
原创 从小到大排序
#include int main (){int i,j,t;int a[10];printf("请输入一串数:");for(j=0;jscanf("%d",&a[j]);for(i=0;i{for(j=0;j{if(a[j]{t = a[j];a[j] = a[j-1];a[j-1] = t;}}}for(j=0;j
2015-04-16 22:12:38 638
原创 周期数判断20150416
#include #include int main(){ char a[10];int j,c;while(1){printf("请输入一组数:");scanf("%s",&a); int b = strlen(a); int i; for(i = 1; i { if(0 == b %
2015-04-16 16:41:11 483 1
原创 C++第二十题20150412
#include#includeint main (){int i;float a;i = 0;for(a=200;ai++;printf("%d年\n",i);return 0;}
2015-04-12 14:48:29 385
原创 C++第十九题20150412
#includevoid f(unsigned int x){unsigned int flag;do{flag = x%2;x = x/10;}while(x && ((!flag)==x%2));if(x==0)printf("满足交替规律\n");elseprintf("不满足交替规律\n");}int main(){unsigne
2015-04-12 14:22:23 476
原创 C++第十八题20150410
#includeint main (){ int a,b,n; printf("请输入随机一个正整数:"); scanf("%d",&n); do{ if(n%2==0) a++; else b++; a=a/10; } while(n==0); if(a*b==0) printf("都含有奇偶数字\n"); else
2015-04-10 11:43:30 401
原创 C++第十七题20150410
#include#includeint main (){ int a,b,i,n; a=0; printf("请输入n:\n"); scanf("%d",&n); for(b=2;b { for(i=2;i { if(b%i==0) a++; } if(a==0) printf("2~%d内的质数是%d\n",n,b)
2015-04-10 10:37:53 321
原创 C++第十五题201150409
#include int main (){int i,j,k,n;printf("请输入一个n:\n");scanf("%d",&n);for(i=0;i{for(j=0;jprintf(" ");for(k=0;kprintf(" o");printf("\n");}for(i=0;i{for(j=0;jprintf(" ");
2015-04-09 22:47:45 436
原创 C++第十六题20150408
#includeint main(){int a,b,c;printf("请输入a,b,c:");scanf("%d%d%d",&a,&b,&c);if (a>=b&&b>=c)printf("%d%d%d\n",c,b,a);else if (a>=c&&c>=b)printf("%d%d%d\n",b,c,a);else if (b>=a&&a>=c)
2015-04-08 21:37:59 464 1
原创 C++第十四题20150408
#includeint main(){int i,n;float a,b,c,d,e,f;a = 2;b = 1;i = 1;d = 0;printf("请输入一个n:");scanf("%d",&n);while(i{c = a/b;d = c + d;e = a + b;f = a;a = e;b = f;i++;
2015-04-08 20:50:09 421 1
原创 C++第十三题20150403
#include int main (){ int number = 0; int letter = 0; int x; char c[100]; scanf("%s",c); for (x=0;x { if(c[x] == 42) break; else if((c[x]>=48)&&(c[x] number++; else if
2015-04-03 10:18:08 349
原创 C++第十二题20150330
#include #include int main (){int x = 0;while(x>=0&&x{if((x%2==1)&&(x%3==2)&&(x%5==4)&&(x%6==5)&&(x%7==0))printf("%d\n",x);x++;}return 0;}
2015-03-30 16:51:25 407
原创 C++第六题20150329
#include int main (){int year,i = 0;for(year=1000;year{if(year%4==0){printf(" %d ",year);i++;if(i%3==0)printf("\n");elseprintf("");}elseprintf("");}return 0;}
2015-03-29 17:58:53 330
原创 C++第十题20150327
#include #include int main (){ int year,month; printf("please input year and month"); scanf("%d%d",&year,&month); if(year%4==0) { if(month == 2) printf("29"); else if (month
2015-03-27 11:14:22 468 2
原创 C++第七题20150327
#include #include int main (){ int a,b,c; printf("plesae input a&b"); scanf("%d%d",&a,&b); c = a - b; if(a { if (c%2==0) printf("他们的后继字符是:%d\n",b+1); else printf("他们的前趋字符是:
2015-03-27 11:04:44 449 1
原创 C++第九题20150327
#include #include int main (){ int x,y; printf("please input x&y"); scanf("%d%d",&x,&y); double A; A = sqrt(pow((x-2),2) + pow((y-2),2)); if (A printf("A在圆内"); else if("
2015-03-27 10:43:46 443 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人