1 / 5

בקרת קלט

#include &lt;stdio.h&gt; int main () { int num; printf(&quot;Enter number(0-100)<br>&quot;); if (scanf(&quot;%d&quot;,&amp;num) != 1) { printf(“Input Error<br>”); return 1; } printf(&quot;Very good<br>&quot;); return 0; }. while ( (num &lt; 0) || (num &gt;100) ) { printf(&quot;Enter number(0-100)<br>&quot;);

bly
Download Presentation

בקרת קלט

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. #include <stdio.h> int main () { int num; printf("Enter number(0-100)\n"); if (scanf("%d",&num) != 1) { printf(“Input Error\n”); return 1; } printf("Very good\n"); return 0; } • while ( (num < 0) || (num >100) ) • { • printf("Enter number(0-100)\n"); • if (scanf("%d",&num) != 1) • { • printf(“Input Error\n”); • return 1; • } • } בקרת קלט

  2. #include <stdio.h> int main() { int num; do { printf("Enter number(0-100)\n"); if(scanf("%d",&num)!=1) { printf(“Input Error\n”); return 1; } } while ( (num < 0) || (num >100) ); printf("Very good\n"); return 0; } בקרת קלט – do while

  3. האלגוריתם של אוקלידס למציאת מחלק משותף גדול ביותר • GCD(x,y) = z • Z הוא המספר הגדול ביותר אשר מחלק גם את x וגם את y. • לדוגמא: gcd(3213,24) = 3 • האלגוריתם: • חלק את המספר הגדול בקטן: אם השארית היא 0 אז ה-gcd הוא המספר הקטן וסיימנו. אחרת עבור ל-2. • קח את השארית להיות המספר הקטן ואת המספר הקטן הקודם להיות המספר הגדול ובצע שוב את סעיף 1. מחלק משותף מקסימלי GCD

  4. דוגמת הרצה gcd(3213,24) 3213 % 24 = 21 24 % 21 = 3 21 % 3 = 0 נשים לב שאם x=0 או y=0 אז המחלק המשותף הגדול ביותר הוא פשוט המספר השונה מ-0. = 3 מחלק משותף מקסימלי GCD

  5. #include <stdio.h> int main() { int x, y, gcd, tmp; printf("Please enter two numbers (the larger first)\n"); if (scanf("%d%d",&x,&y) != 2) { printf(“Input Error\n”); return 1; } if (x == 0 || y == 0) { gcd = x+y; printf("The gcd is: %d\n",gcd); return 0; } while( (x %= y) != 0) { tmp = x; x = y; y = tmp; } printf("The gcd is: %d\n",y); return 0; }

More Related