第一篇:6174猜想C语言代码-九院黄伟
6174猜想
1955年,卡普耶卡(D.R.Kaprekar)研究了对四位数的一种变换:任给出四位数k0,用它的四个数字由大到小重新排列成一个四位数m,再减去它的反序数rev(m),得出数k1=m-rev(m),然后,继续对k1重复上述变换,得数k2.如此进行下去,卡普耶卡发现,无论k0是多大的四位数,只要四个数字不全相同,最多进行7次上述变换,就会出现四位数6174.#include
main()
{
int s,a, b, c, d;
int t=0,x;
int m,n;
printf(“请输入一个四位每位不全相同的数:”);
scanf(“%d”, &s);
a=s/1000;
b=s%1000/100;
c=s%100/10;
d=s%10;
for(x=0;;x++){
if(x==0){
if(a==b&&a==c&&a==d&&b==c&&b==d&&c==d){
printf(“输入的四位不合法!n”);break;
}
}
a=s/1000;b=s%1000/100;c=s%100/10;d=s%10;
if(a
if(b if(c if(a if(b if(a m=a*1000+b*100+c*10+d; n=a+b*10+c*100+d*1000; if(m-n==6174){ printf(“s=%d-%d=%dn”, m, n, m-n); printf(“结束!n”);break; }else{ s=m-n; printf(“s=%d-%d=%dn”, m, n, s); }}} 考拉兹猜想 考拉兹猜想,又称为3n+1猜想、角谷猜想、哈塞猜想、乌拉姆猜想或叙拉古猜想,是由日本数学家角谷静夫发现,是指对於每一个正整数,如果它是奇数,则对它乘3再加1,如果它是偶数,则对它除以2,如此循环,最终都能够得到1。 #include main() { int n;//存储该自然数 int i; printf(“请输入一个自然数:”); scanf(“%d”,&n); for(i=1;;i++){ if(n==1){ printf(“第%d步:n=%dn”,i,n);break; }else if(n%2==0){ printf(“第%d步:n=%d÷2=%dn”,i,n,n/2); n=n/2; }else if(n%2==1){ printf(“第%d步:n=%d×3+1=%dn”,i,n,n*3+1); n=n*3+1; } } } #include “stdio.h” #include void main(){ int n=0;struct course *head=NULL;void insert(struct course **head,struct course *cou);void Print(struct course **head,int *n);void Modify(struct course **head,int *n);void Require(struct course **head);void Creat(struct course **head,int *n);void Delete(struct course **head,int *n);void Fun(struct course **head,int *n); Fun(&head,&n);} void insert(struct course **head,struct course *cou){ struct course *p0,*p1,*p2;p2=p1=*head;p0=cou;if(*head){ while((p0->semester>p1->semester)&&(p1->next)) { p2=p1; p1=p1->next; } if(p0->semester semester) { if(*head==p1)*head=p0; else p2->next=p0; p0->next=p1;} else { if(p0->semester==p1->semester){ while((p0->cID>p1->cID)&&(p1->next)&&(p0->semester==p1->semester)) { } if(p0->semester!=p1->semester){ } else { if(p0->cID<=p1->cID){ if(*head==p1)*head=p0;else p2->next=p0;p2=p1;p1=p1->next;p2->next=p0;p0->next=p1; p0->next=p1; } else {p1->next=p0;p0->next=NULL;} } } else {p1->next=p0;p0->next=NULL;} } } else { *head=p0; p0->next=NULL;} } void Print(struct course **head,int *n){ struct course *p;p=*head;if(*head){ if(*n==1)printf(“nThis %d record is:n”,*n); else printf(“nThese %d records are:n”,*n); printf(“semester cID name creditn”); do { printf(“%-10d%-10d%-18s%-12.1f n”,p->semester,p->cID,p->name,p->credit); p=p->next; }while(p!=NULL);} else printf(“nList null!n”);} void Modify(struct course **head,int *n){ struct course *p,*p2;int cID;if(*head){ Print(head,n);while(1){ printf(“nPlease input the cID which you want to modify:”); scanf(“%d”,&cID);p2=p=*head;while(p->next&&(cID!=p->cID)){ p2=p; p=p->next;} if(cID==p->cID){ printf(“Please input the new cID(1~60):”); scanf(“%d”,&p->cID); while(p->cID<0||p->cID>60) { printf(“nError!”); printf(“nPlease input the new cID(1~60):”); scanf(“%d”,&p->cID); } printf(“Please input the new semester(1~8):”); scanf(“%d”,&p->semester);while(p->semester<0||p->semester>8) { printf(“nError!”); printf(“nPlease input the new semester(1~8):”); scanf(“%d”,&p->semester); } printf(“Please input the new credit:”); scanf(“%f”,&p->credit); printf(“Please input the new name:”); scanf(“%s”,p->name); if(p==*head)*head=p->next; else p2->next=p->next; insert(head,p); break; } else printf(“%d not been found!n”,cID); } } else {printf(“nList null!n”);} } void Require(struct course **head){ struct course *p;float sum=0;int sem,i=0;printf(“nPlease input the semester which is required:”); scanf(“%d”,&sem);p=*head;while(p){ if(sem==p->semester) { i++;if(i==1)printf(“nsemester cID name creditn”);printf(“%-10d%-10d%-18s%-12.1f n”,p->semester,p->cID,p->name,p->credit); sum=sum+p->credit; } p=p->next;} printf(“The sum of credit in this term is:%.1fn”,sum);} void Creat(struct course **head,int *n){ struct course *p1;while(1){ p1=(struct course *)malloc(LEN); printf(“Please input the cID(1~60):”); scanf(“%d”,&p1->cID); while(p1->cID<0||p1->cID>60) { printf(“nError!”); printf(“nPlease input the cID(1~60):”); scanf(“%d”,&p1->cID); } if(p1->cID==0)break; printf(“Please input the semester(1~8):”); scanf(“%d”,&p1->semester); while(p1->semester<0||p1->semester>8) { printf(“nError!”); printf(“nPlease input the semester(1~8):”);scanf(“%d”,&p1->semester); } } } printf(“Please input the credit:”);scanf(“%f”,&p1->credit);printf(“Please input the name:”);scanf(“%s”,p1->name);insert(head,p1);*n=*n+1;printf(“nYou can continue until the cID is ”0“!n”);Print(head,n);void Delete(struct course **head,int *n){ struct course *p1,*p2;int cID;Print(head,n);if(*head){ printf(“Please input the cID of the course which you want to delete:”);scanf(“%d”,&cID);p1=*head; while(cID!=p1->cID&&p1->next!=NULL) { p2=p1; p1=p1->next; } if(cID==p1->cID) { if(p1==*head)*head=p1->next; else p2->next=p1->next; printf(“Have delete cID:%dn”,cID); *n=*n-1; } else printf(“%d not been found!n”,cID);} } void Fun(struct course **head,int *n){ char num; while(1) { system(“cls”); puts(“**************** Main Menu ******************”); puts(“* 1.Add Records 2.Print Records *”); puts(“* 3.Delete Records 4.Modify Records *”); puts(“* 5.Require Records 6.Exit *”); printf(“Please input your choice: ”); scanf(“%d”,&num); switch(num) { case 1:Creat(head,n);break; case 2:Print(head,n);break; case 3:Delete(head,n);break; case 4:Modify(head,n);break; case 5:Require(head);break;case 6:exit(0);break; default: break; } printf(“nPress ”Enter“ to continue!”);getchar();getchar(); } } C语言验证哥德巴赫猜想(100以内) #include “stdafx.h” #include “stdio.h” int ss(int i) { int j; if(i <= 1) return 0; if(i == 2) return 1; for(j = 2;j < i;j++) { if(i % j == 0) return 0; else if(i!= j + 1) continue; else return 1; } } int main() { int i, j, k, flag1, flag2, n = 0;for(i = 6;i < 100;i += 2) } {} return 0;for(k = 2;k <= i / 2;k++){} j = i-k;flag1 = ss(k);if(flag1){} flag2 = ss(j);if(flag2){} printf(“%3d=%3d+%3d,”, i, k, j);//输出结果 n++;if(n % 5 == 0)//每个数自动换一行 printf(“n”);//调用ss函数判断另一个数是否为素数 //如果都是素数//调用ss函数判断当前数是否为素数//循环判断是否为素数//如果等于返回//如果小于等于返回 #include #include int is_prime(int); main(){ } //验证[a,b]区间内的整数是否符合猜想 int yanzhengGDBH(int a,int b){ } int gdbh(int n){//验证偶数n能否分解成两个素数 int a;a=3;while(a } } if(is_prime(a)){// 判断a是否是素数} a++;if(is_prime(n-a)){// 判断n-a是否是素数} printf(“OK!%d=%d+%dn”,n,a,n-a);return 1;printf(“gedebahe ,ni cuo le!n”);return 0; int is_prime(int n){//判断n是否是素数 } int i=2;if(n<2)return 0;while(i<=sqrt(n)){//2-根号n,找n的因子} return 1;//i是n的因子,不是素数 if(n%i==0){} i++;return 0;//i是n的因子,不是素数第二篇:考拉兹猜想C语言代码-九院黄伟
第三篇:C语言课程设计代码
第四篇:C语言验证哥德巴赫猜想
第五篇:c语言 哥德巴赫猜想2