Centos8下docker自動化安裝指令碼
阿新 • • 發佈:2022-04-15
task 1
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <windows.h> #define N 80 void printText(int line, int col, char text[]); void printSpaces(int n); void printBlankLines(int n); int main() { int line, col, i; char text[N] = "hi, May~"; srand(time(0));for(i=1; i<=10; ++i) { line = rand()%25; col = rand()%80; printText(line, col, text); Sleep(1000); } system("pause"); return 0; } void printSpaces(int n) { int i; for(i=1; i<=n; ++i) printf(" "); } void printBlankLines(int n) { int i; for(i=1; i<=n; ++i) printf("\n"); } void printText(int line, intcol, char text[]) { printBlankLines(line-1); printSpaces(col-1); printf("%s",text); }
程式功能:列印十個hi,May~,間隔的行數在0~24之間隨機取值,列數在0~79之間隨機取值
task2-1
#include <stdio.h> #include<stdlib.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)); system("pause"); return 0; } long long fac(int n) { static long long p = 1; printf("p=%11d\n",p); p = p * n; return p; }
task2-2
#include <stdio.h> #include<stdlib.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); system("pause"); return 0; } int func(int a, int b) { static int m = 0, i = 2; i += m + 1; m = i + a + b; return m; }
static 變數
1.作為靜態區域性變數
靜態儲存,編譯器在靜態儲存區為它分配記憶體單元。它的值不會因為函式呼叫結束而清除,下次被呼叫時,它的值是上次被呼叫後的值。
2.作為靜態全域性變數
可以被該檔案所有函式訪問。儲存位置和區域性變數特性相同
task3
#include <stdio.h> #include<stdlib.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); } system("pause"); return 0; } long long fun(int n) { if(n==1) return 1; else return fun(n-1)*2+1;
}
task4
#include<stdio.h> #include<stdlib.h> int i; void hanoi(unsigned n,char from,char to,char temp); void move(unsigned n,char from,char to); int main() { unsigned n; while(scanf("%u",&n)!=EOF) { i=0; hanoi(n,'A','C','B'); printf("一共移動了%d次",i);} system("pause"); } void hanoi(unsigned n,char from,char to,char temp) { if(n==1) move(n,from,to); else { hanoi(n-1,from,temp,to); move(n,from,to); hanoi(n-1,temp,to,from);} } void move (unsigned n,char from,char to) { i++; printf("%u:%c-->%c\n",n,from,to); }
task3-5
#include<stdio.h> #include<stdlib.h> int is_Prime(int n); int main() { int n,p,q,pflag=0,qflag=0; for(n=4;n<=20;n+=2) { for(p=2;p<=n;p++) {q=n-p; pflag=is_Prime(p); qflag=is_Prime(q); if(pflag==1&&qflag==1) { printf("%d=%d+%d\n",n,p,q); break; } } } system("pause"); } int is_Prime(int n) { int i; for(i=2;i<n-1;i++) { if(n%i==0) break; } if(i>=n-1) return 1; else return 0; }
task6
#include<stdio.h> #include<stdlib.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:"); } system("pause"); } long fun(long s) { long i,p,t=0,x=0,m; p=s; while(p!=0) { i=p%10; if(i%2==1) t=t*10+i; p/=10; } while(t!=0) { m=t%10; x=x*10+m; t/=10; } return x; }