《算法競賽入門指導》Ch2的思考題2
題目2。下面的程序運行結果是什麽?“!=”運算符表示“不相等”。提示:請上機實
驗,不要憑主觀感覺回答。
#include<stdio.h>
int main()
{
double i;
for(i = 0; i != 10; i += 0.1)
printf("%.1f\n", i);
return 0;
}
事實上,這個算法會一直滾下去,就想死循環。
原來是因為
It is due to IEEE floating point standard.
0.1 + 0.2 = 0.3 => FALSE - Expected: 0.3 | Real: 0.30000000000000004
《算法競賽入門指導》Ch2的思考題2
相關推薦
《算法競賽入門指導》Ch2的思考題2
運行 std clas it is 程序 exp 提示 als ng- 題目2。下面的程序運行結果是什麽?“!=”運算符表示“不相等”。提示:請上機實驗,不要憑主觀感覺回答。#include<stdio.h>int main(){double i;for(i =
算法競賽入門經典第2版 第1章
計算 const 解決問題 pause 會有 return 數學 getchar() scanf 學習目標: 熟悉C語言程序的編譯和運行 學會編程計算並輸出常見的算術表達式的結果 掌握整數和浮點數的含義和輸出方法、聲明方法、讀入方法 掌握數學函數的使用方法
隨機生成數,摘自算法競賽入門經典P120-P123測試STL。
space urn algo std ace ear str stream stl //#include<bits/stdc++.h> #include<cstring> #include<iostream> #include<c
拓撲排序((算法競賽入門經典)劉汝佳)
沒有 -1 nts adjacency lag 過大 content tail popu 轉載請註明出處:http://blog.csdn.net/u012860063?viewmode=contents 【分析】(小白) 把每一個變量看成
算法競賽入門經典-訓練指南(10881-Piotr's Ants)
log else char order 數組保存 logs code color 速度 題目大意: 一根長度為L的木棍一堆螞蟻爬,向左或向右,速度都為1,若兩螞蟻碰撞則同時轉頭(轉身時間忽略不計),問T時間之後每只螞蟻的位置; 輸入:t,(t個樣例),每個樣例輸入 L,T,
C/C++算法競賽入門經典Page11 例題1-5 三整數排序
輸出 例題 c++ 一個 臨時 code include can 完整 題目:輸入3個整數,從小到大排序後輸出 樣例輸入: 20 7 33 樣例輸出: 7 20 33 首先,先聲明三個整數a,b,c和一個臨時變量t: int a,b,c,t;//1,b,c為三個整數,
C/C++算法競賽入門經典Page9 例題1-4 雞兔同籠
blog 兩個 pan scan spa printf col 判斷 () 題目:雞和兔總數:n,總腿數:m.輸入n,m,輸出雞和兔分別的數量;無解則輸出"No answer" 樣例輸出1: 14 32 樣例輸出1: 12 2 樣例輸入2: 10 16 樣例輸出2: No
算法競賽入門經典_4.3_遞歸
什麽 std 內部 start 分組 調試工具 war 運行 自己 看代碼 #include <stdio.h> int f(int n){ return n == 0?1:f(n-1)*n; } int main() { printf("%
【算法競賽入門經典】7.3子集生成【增量構造法】【位向量法】【二進制法】
subset 3.2 code == tdi style 構造 算法 nbsp 7.3.1增量構造法 思路:一次選出一個元素放到集合中。自己對於遞歸的理解還是不夠,這裏雖然沒有明確給出遞歸停止條件,但是如果無法繼續添加元素,就不會再繼續遞歸,然後就是我頭疼的回溯啦。
C/C++算法競賽入門經典Page16 習題1-4 正弦和余弦
pan 輸出 定義 c++ col return 算法競賽入門經典 算法 printf 題目:輸入正整數 n(n<360),輸出n度的正弦余弦數值。提示:用數學函數 需要用到的數學函數: acos,sin,cos 函數頭文件:math.h #include <
C/C++算法競賽入門經典Page16 習題1-3 連續和
n) 練習 clu amp ... blog 變量 入門經典 c++ 題目:輸入正整數 n,輸出1+2+3+...+n的值。提示:目標是解決問題,而不是練習編程 為了輸出1+2+3+...+n,可以使用首項加末項乘以項數除以2的公式 (1)聲明1+2+3+...+n的和m,
C/C++算法競賽入門經典Page16 習題1-5 打折
span 博客 保留 double int 保留兩位小數 c++ 小數 pan 題目:一件衣服 95元,若消費滿300元,可打八五折。輸入購買衣服件數,輸出需要支付的金額(單位元),保留兩位小數. 通過分支結構可以判斷是否要打八五折. (1)聲明衣服件數a,需要支付的金額b
C/C++算法競賽入門經典Page16 習題1-6 年份
blog std ear code http ret 判斷 ++ class 題目:輸入年份,判斷是否為潤年,如果是,輸出yes,否,輸出no。提示:簡單的除以4是不夠的 分析閏年的條件: (1)能被4整除. (2)整百的年份一定要能被400整除. 步驟: (1)聲明一個i
C/C++算法競賽入門經典Page16 習題1-6 三角形
include 是否 angle not 習題 bsp 如果 著作權 能夠 題目:輸入三角形 3 條邊長度值(均為正整數),判斷是否能為直角三角形的3個邊長。如果可以,則輸出yes,不能輸出no,如果無法構成三角形,則輸出 not a triangle 分析能構成三角形的條
算法競賽入門經典——讀書筆記day1
計算 conio.h 方式 需要 1-1 font 包括 讀書筆記 發現 1-1:整數值用%d輸出,實數用%f輸出。 1-2:整數/整數=整數,浮點數/浮點數=浮點數。 1-3:scanf中的占位符和變量的數據類型應一一對應,且每個變量前需要加&符號。 1-4:在算
隨筆筆記 算法競賽入門經典 ch3
-s strong har ont 自動停止 經典 scanf pan 讀取 關於讀取 scanf() 讀取到空格自動停止 getchar() 讀取結束返回 EOF (整型) 隨筆筆記 算法競賽入門經典 ch3
開燈問題(算法競賽入門經典)
地方 wrong ios iomanip 報錯 man wro 裏的 memset #include <stdio.h>#include "stdafx.h"#include <iostream>#include<time.h>#incl
算法競賽入門經典題解——第三章 3-3數數字 UVa1225
() %d 入門 scan clu amp uva ++ tdi 我的思路是打表,但不一次性打出所有。目前已經計算出的最大n標記為max,假如一次輸入為n=13,就把n=max+1到13的結果都儲存到二維數組中。max初始為0 坑:每行輸出末尾不能有空格,但必須換行(包括最
算法競賽入門經典題解——第三章 3-4 周期串UVa455
() sca clas pan 可能 span amp tdi ++ 思路:遍歷可能的周期,比較s[k]與s[k%i](其中i為周期) #include <stdio.h> #include <stdlib.h> #include<str
[算法競賽入門經典] Crossword Answers ACM/ICPC World Finals 1994,UVa232
init als grid lists cross for each icpc tput std Description A crossword puzzle consists of a rectangular grid of black and white squares