#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 = %lld\n", n, f); } return 0; } long long fun(int i){ long long s=1; while(i!=0){ s=s*2; i=i-1; } s=s-1; return s; }
2
#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! = %lld\n", i, fac(i)); return 0; } // 函数定义 long long fac(int n) { static long long p = 1; p = p*n; return p; }
#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! = %lld\n", i, fac(i)); return 0; } // 函数定义 long long fac(int n) { static long long p = 1; printf("p = %lld\n", p); 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); }
3
#include <stdio.h> #define N 1000 int fun(int n,int m,int bb[N]) { int i,j,k=0,flag; for(j=n;j<=m;j++) { flag=1; for(i=2;i<j;i++) if(j%i==0) { flag=0; break; } if(flag!=0) bb[k++]=j; } return k; } int main(){ int n=0,m=0,i,k,bb[N]; scanf("%d",&n); scanf("%d",&m); for(i=0;i<m-n;i++) bb[i]=0; k=fun(n,m,bb); for(i=0;i<k;i++) printf("%4d",bb[i]); return 0; }
4
#include <stdio.h> void dec2n(int x, int n); // 函数声明 int main() { int x; printf("输入一个十进制整数: "); scanf("%d", &x); dec2n(x, 2); // 函数调用: 把x转换成二进制输出 dec2n(x, 8); // 函数调用: 把x转换成八进制输出 dec2n(x, 16); // 函数调用: 把x转换成十六进制输出 return 0; } // 函数定义 // 功能: 把十进制数x转换成n进制,打印输出 // 补足函数实现 void dec2n(int x, int n) { int k = 0, a[100],t,i; while(x!=0){ t=x%n; x=x/n; a[k]=t; k++; if(t>10) switch(a[k]){ case 10:a[k]=‘A‘;break; case 11:a[k]=‘B‘;break; case 12:a[k]=‘C‘;break; case 13:a[k]=‘D‘;break; case 14:a[k]=‘E‘;break; case 15:a[k]=‘F‘;break; }} printf("%d进制: ",n); for(i=k-1;i>=0;i--){ printf("%d",a[i]); } printf("\n"); }
原文:https://www.cnblogs.com/qzxzlsw/p/14715675.html