c语言oj角谷猜想函数专题,角谷猜想 c语言

1,角谷猜想 c语言#include<stdio.h>int main() int n, t, m = 0; scanf("%d", &n); t = n; printf("%d ", t); while(t !制= 1) zdif(t % 2)t = t * 3 + 1;elset /= 2;m++;printf("%d ", t); } printf("\n%d calculate %d times,the answer become to 1!\n", n, m); return 0;}
2,验证角谷猜想 c语言if (count!=0)printf("\b\n");加个\b退位if (count!=0)printf("\b\n"); 加个\b退位#includemain() {int a,b,count; printf("请输入a的值,以便检验角谷猜想 。\na="); scanf("%d",&a); b=a; while (a!=1) {if (a>1&&a%2==0) {a=a/2 ;printf ("→%d\n",a);} else {a=3*a+1;printf("→%d\n",a);} count++;}printf("%d需经过%d步才得到1.",b,count);} //如果能够逆推出,比方说,23的下一步是70,那么都有哪些数的下一步是70?如此逆推,就能写成一棵"数论树".
3,求角谷猜想C语言程序输入一个正整数输出此整数回到1经过的步#include<stdio.h>main() int n,c=0; printf("输入一个小于等于一万的整数:"); scanf("%d",&n); if(n>10000&&n<0) printf("输入错误请重新输入!"); while(n!=1)if(n%2==0)n=n/2;elsen=n*3+1;c++; } printf("%d\n",c);}#include<stdio.h>main() int n=0; int num; doprintf("please input a integrate(num<=10000):");scanf("%d",&num); } while(num>10000); while(num!=1)if(num%2==1)num=num*3+1;elsenum=num/2;n++; } printf("n=%d\n",n);}#include<stdio.h>main() int n=0; int num; doprintf("please input a integrate(num<=10000):");scanf("%d",&num); } while(num>10000); while(num!=1)if(num%2==1)num=num*3+1;elsenum=num/2;n++; } printf("n=%d\n",n);}#includemain() int n=0; int num; doprintf("please input a integrate(num<=10000):");scanf("%d",&num); } while(num>10000); while(num【c语言oj角谷猜想函数专题,角谷猜想 c语言】
4,c语言与角谷猜想#include<stdio.h>main() printf("请输入a的值,以便检验角谷猜想 。\na="); scanf("%d",&a); b=a; while (a!=1)else count++;}printf("%d需经过%d步才得到1.",b,count);}//如果能够逆推出 , 比方说,23的下一步是70,那么都有哪些数的下一步是70?如此逆推,就能写成一棵"数论树".代码比较简单,各语句意义见注释 。。。#include int main(int argc, char *argv[]) int i; /*定义要处理的变量*/ scanf("%d", &i); /*输入变量值*/ while(i != 1) if(i%2)/*奇数*/ printf("%d*3+1=%d\n", i, i*3+1); /*按题目要求的格式打印出来*/ i = i*3+1; /*更新变量值*/ } else /*偶数*/ printf("%d/2=%d\n", i, i/2); /*按题目要求的格式打印出来*/ i = i/2; /*更新变量值*/ } } printf("end\n"); /*最后打印end*/ return 0; }另外几个测试结果图片://希望可以帮到您#include <stdio.h>#include <stdlib.h>int main() int i; static int count=0; printf("Number:\t"); scanf("%d",&i); doif(i%2==0)count++;printf("Step %3d -> %d = %d / 2\n",count,i/2,i);i=i/2;}elsecount++;printf("Step %3d -> %d = 3 x%d + 1\n",count,3*i+1,i);i=i*3+1;} }while(i!=1); return 0;}

    推荐阅读