C語言練習1

2021-09-12 22:14:01 字數 1288 閱讀 5302

1.給定兩個整形變數的值,將兩個值的內容進行交換。

#define   _crt_secure_no_warnings

#include #include int main()

2.不允許建立臨時變數,交換兩個數的內容

#define   _crt_secure_no_warnings

#include #include int main()

3.求10 個整數中最大值。(方法1)

#define   _crt_secure_no_warnings

#define n 10

#include int main()

printf("max=%d\n", max);

system("pause");

return 0;

}

3.求10 個整數中最大值。(方法2)
#define _crt_secure_no_warnings

#include #include void max(int arr,int max) }}

int main() ;

printf("請輸入10個整數:");

for (int i = 0; i < 10; ++i)

max(arr,max);

printf("最大的數是 %d\n", arr[max]);

system("pause");

return 0;

}

4.將三個數按從大到小輸出。

#define   _crt_secure_no_warnings

#include #include int main()

} else

} }system("pause");

return 0;

}

5.求兩個數的最大公約數。

#define _crt_secure_no_warnings

#include #include int main()

while (y != 0)

printf("%d", x);

system("pause");

return 0;

}

C語言練習1

分別將結果輸出到檔案out.dat這一項還未實現,c語言檔案內容還需要複習。請編寫乙個函式 jsvalue int m,int k,int xx 該函式的功能是 將大於整數 m 且緊靠 m 的 k 個素數存入陣列 xx 傳回。最後呼叫函式 writedat 讀取 10 組資料,分別得出結果且把結果輸...

C語言練習1

題目描述 寫乙個函式返回引數二進位制中 1 的個數 比如 十進位制15即二進位制 0000 1111 有4 個 1 程式原型 int count one bits unsigned int value 問題分析 將十進位制轉化為2進製,轉化的同時判斷1的個數,最後將計算結果返回 int count ...

C語言練習 1

現在來通過練習來進一步了解c語言這種程式語言。首先第一題 列印100 200之間的素數 要列印素數首先要知道素數的概念,即在大於1的自然數中,除了1和它本身以外不再有其他因數。那麼可以確認程式設計思路,即通過迴圈結構,讓100 200之間的每乙個整數都與每乙個比自身小的正數相除取餘,如果餘數為0則證...