משהו מעניין מאוד בc
כל מתכנת מתחיל בc יוכל להבין את הקוד הבא:
כל מתכנת מתחיל בc יוכל להבין את הקוד הבא:
#include <stdio.h> #include <math.h> int main(){ int TheNum, Pow3, TheSer, TheSerSum, Check; Pow3 = 1; TheSerSum = 1; for (TheNum = 1; TheNum<100000 ; TheNum++) /*it was should be - Pow3 >= TheSerSum.*/ { TheSerSum = 1; for (TheSer = 1; TheSer <= TheNum; TheSer++) { TheSerSum = TheSerSum * TheSer; } Pow3 = pow(3,TheNum); if (Pow3 < TheSerSum) { if (Check == 1) { printf("Its Still True For %d\n", TheNum); } else { printf("Great we found The first Num, its - %d\n",TheNum); } Check = 1; } else printf("Still NOTHING (%d)\n",TheNum); } }
ראו מה הפלט עבור קוד זה:Still NOTHING (1) Still NOTHING (2) Still NOTHING (3) Still NOTHING (4) Still NOTHING (5) Still NOTHING (6) Great we found The first Num, its - 7 Its Still True For 8 Its Still True For 9 Its Still True For 10 Its Still True For 11 Its Still True For 12 Its Still True For 13 Its Still True For 14 Its Still True For 15 Its Still True For 16 Still NOTHING (17) Still NOTHING (18) Still NOTHING (19) Its Still True For 20 Its Still True For 21 Its Still True For 22 Its Still True For 23 Its Still True For 24 Its Still True For 25 Its Still True For 26 Its Still True For 27 Its Still True For 28 Its Still True For 29 Its Still True For 30 Its Still True For 31 Still NOTHING (32) Still NOTHING (33) Its Still True For 34 Its Still True For 35 Its Still True For 36
נראה שהמחשב טועה ! אפשר להוכיח באינדוקציה שאחרי 7 הכל אמור להחזיר true למישהו יש הסבר לפלט הזה? דניאל