实验仨(....)
作者:互联网
#include <stdio.h> long fun(long s); int main() { long s,t; printf("Enter a number: "); while (scanf("%ld", &s)!=EOF) { t=fun(s); printf("new number is:%ld\n\n",t); printf("Enter a number: "); } return 0; } long fun(long s) { long i,j=1,k=0; while(s!=0) { i=s%10; if(i%2!=0) { k=k+i*j; j=j*10; } s=s/10; } return k; }
功能:在随机位置间隔打印十个“hi,May~”
#include <stdio.h> long long fac(int n); int main() { int i,n; printf("Enter n: "); scanf("%d",&n); for(i=1;i<=n;++i) printf("%d!=%11d\n",i,fac(i)); return 0; } long long fac(int n) { static long long p=1; p=p*n; return p; }
#include <stdio.h> int func(int,int); int main() { int k=4,m=1,p1,p2; p1=func(k,m); p2=func(k,m); printf("%d,%d\n",p1,p2); return 0; } int func(int a,int b) { static int m=0,i=2; i+=m+1; m=i+a+b; return m; }
局部static变量的特性:静态局部变量在程序执行到该对象的声明处时被首次初始化,以后的函数调用不再进行初始化
#include <stdio.h> long long fun(int n); int main() { int n; long long f; while(scanf("%d",&n)!=EOF) { f=fun(n); printf("n = %d,f = %11lld\n", n, f); } return 0; } long long fun(int n) { int i; long long f,j=1.0; for(i=1;i<=n;i++) { j=j*2; } f=j-1; return f; }
#include <stdio.h> void hanoi(unsigned int n,char from,char temp,char to); void moveplate(unsigned int n,char from,char to); int i; int main() { unsigned n; while(scanf("%u",&n)!=EOF) { i=0; hanoi(n,'A','B','C'); printf("\n一共移动%d次\n",i); } return 0; } void hanoi(unsigned int n,char from,char temp,char to) { if(n==1) moveplate(n,from,to); else { hanoi(n-1,from,to,temp); moveplate(n,from,to); hanoi(n-1,temp,from,to); } } void moveplate(unsigned n,char from,char to) { i++; printf("第%u个盘子:%c-->%c\n",n,from,to); }
include <stdio.h> int is_prime(int n); int main() { int i,j; for(i=4;i<=20;i++) { if(i%2==0) { for(j=2;j<i;j++) { if(is_prime(j)==1 && is_prime(i-j)==1) { printf("%d=%d+%d\n",i,j,i-j); break; } } } } return 0; } int is_prime(int n) { int i; for(i=2;i<=n;i++) if(n%i==0) break; if(i==n) return 1; else return 0; }
#include <stdio.h> long fun(long s); int main() { long s,t; printf("Enter a number: "); while (scanf("%ld", &s)!=EOF) { t=fun(s); printf("new number is:%ld\n\n",t); printf("Enter a number: "); } return 0; } long fun(long s) { long i,j=1,k=0; while(s!=0) { i=s%10; if(i%2!=0) { k=k+i*j; j=j*10; } s=s/10; } return k; }
标签:return,int,....,long,char,实验,printf,fun 来源: https://www.cnblogs.com/YH32602799/p/16190084.html