資源簡介
C++實戰源碼-整數加減法練習(入門級實例042).zip
代碼片段和文件信息
//?Account.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?
#include?
#include?
int?main()
{
int?a?b?c?sign?max; ?//定義基本整型變量
char?sign1; ?//定義字符型變量
printf(“請輸入運算符(1或者其他數字1表示:-其他表示數字:+):\n“);
scanf(“%d“?&sign); ?//輸入函數,輸入數據賦給sign
printf(“請輸入加減時的最大范圍(<10000):\n“);
scanf(“%d“?&max); ?//輸入函數,輸入數據賦給max
srand((unsigned?long)time(0)); ?//系統時鐘設定種子
a?=?rand()?%?max; ?//產生小于max的隨即數并賦給a
b?=?rand()?%?max; ?//產生小于max的隨即數并賦給b
while?((a? {
a?=?rand()?%?max;
b?=?rand()?%?max;
}
sign1?=?(sign?==?1???‘-‘?:?‘+‘); ?//將選擇的符號賦給sign1
printf(“\n%d%c%d=“?a?sign1?b);
scanf(“%d“?&c); ?//輸入運算結果
if?((sign?==?1)?&&?(a-b?==?c)?||?(sign?!=?1)?&&?(a+b?==?c)) ?//判斷運算結果是否等于正確答案
printf(“OK!\n“); ?//等于正確答案輸出ok
else
printf(“答錯了!\n“); ?//不等于正確答案輸出錯誤
getch();
re
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1181??2010-09-08?15:47??Account\Account.cpp
?????文件????????4548??2010-09-08?15:35??Account\Account.dsp
?????文件?????????539??2010-09-08?15:35??Account\Account.dsw
?????文件?????????294??2010-09-08?15:35??Account\StdAfx.cpp
?????文件?????????769??2010-09-08?15:35??Account\StdAfx.h
- 上一篇:C++實戰源碼-打地鼠
- 下一篇:C++實戰源碼-文字跟隨鼠標
評論
共有 條評論