1. 程式人生 > 實用技巧 >關於XFS檔案系統概述

關於XFS檔案系統概述

實驗任務1

結論 不能,返回值有兩個,不方便如此設計。

實驗任務2

 1 #include <stdio.h>
 2 long long fac(int);
 3 main()
 4 {
 5     int i,n;
 6     printf("Enter n:");
 7     scanf("%d",&n);
 8     for(i = 1; i <= n; i ++)
 9         printf("%d! = %lld\n", i, fac(i));
10 }
11 long long fac(int n)
12 {
13     static long
long p = 1; 14 15 p = p * n; 16 return p; 17 }

ex2_2

p1 = 8, p2 = 17;

結論

static變數使變數值穩定,不會迴圈一次就清除。

實驗任務3

 1 #include <stdio.h>
 2 
 3 #define N 1000
 4 int fun(int n,int m,int bb[N]) 
 5 {
 6     int i, j, k = 0, flag;
 7     
 8     for(j = n; j <= m; j ++) 
 9     {
10           flag = 1
; 11 for(i = 2; i < j; i ++) 12 if(j % i == 0) 13 { 14 flag = 0; 15 break; 16 } 17 if(flag == 1) 18 bb[k ++]=j; 19 } 20 return k; 21 } 22 23 int main() 24 { 25 int n = 0, m = 0, i, k, bb[N];
26 27 scanf("%d",&n); 28 scanf("%d",&m); 29 30 for(i = 0; i < m - n;i ++) 31 bb[i]=0; 32 33 k = fun(n, m, bb); 34 35 for(i = 0; i < k; i ++) 36 printf("%4d", bb[i]); 37 38 return 0; 39 }

實驗任務4

 1 #include <stdio.h>
 2 long long fun(int n);   
 3 char th(int n);
 4 int main() {
 5     int n;
 6     long long f;
 7     
 8     while(scanf("%d", &n) != EOF) {
 9         f = fun(n);  
10         printf("n = %d, f = %lld\n", n, f);
11     }
12     
13     return 0;
14 }
15 
16 long long fun(int n)
17 {
18     if(n == 1)
19         return 1;
20     else if(n <= 63)
21         return 2 * fun(n - 1) + 1;
22     
23 }

實驗任務5

#include <stdio.h>

void draw(int n, char symbol);   

#include <stdio.h> 
int main() {
    int n, symbol;
    
    while(scanf("%d %c", &n, &symbol) != EOF) {
        draw(n, symbol);  
        
        printf("\n");
    }
    
    return 0;
} 


void draw(int b,char c)
{
    int n, i, s;
    for(n = 1; n <= b; n ++)
        {
        for(s = 1; s <= b - n; s ++)
            printf(" ");
            for(i = 1; i <= 2 * n - 1; i ++)
            {
            printf("%c",c);
            if(i == 2 * n - 1)
            printf("\n");
            }
    }
    printf("\n");
    return;
    
}