int int main int a b Read two
int – פעולות חשבון int main() { int a, b; /* Read two integer numbers. */ printf(“Enter two integersn”); scanf(“%d%d”, &a, &b); /* Perform some calculations. */ printf(“%d + %d = %d”, a, b, a+ b); printf(“%d - %d = %d”, a, b, a - b); printf(“%d * %d = %d”, a, b, a * b); printf(“%d / %d = %d”, a, b, a / b); printf(“%d mod %d = %d”, a, b, a % b); return 0; }
פלט - תוכנית Enter two integers 42 4+2=6 4 - 2=2 4*2 = 8 4/2 =2 4 mod 2 = 0
פלט - תוכנית Enter two integers 7 3 7 + 3 = 10 7 - 3=4 7 * 3 = 21 7/3 = 2 7 mod 3 = 1
float – פעולות חשבון int main() { float x, y; printf (“Enter two numbers: n”); scanf (“%f%f”, &x, &y); /* Perform some calculations. */ printf(“%f + %f = %f”, x, y, x+ y); printf(“%f - %f = %f”, x, y, x- y); printf(“%f * %f = %f”, x, y, x * y); printf(“%f / %f = %f”, x, y, x / y); return 0; }
פלט - תוכנית Enter two numbers: 42 4. 000000 + 2. 000000 = 6. 000000 4. 000000 - 2. 000000 = 2. 000000 4. 000000 * 2. 000000 = 8. 000000 4. 000000 / 2. 000000 = 2. 000000
פלט - תוכנית Enter two numbers 7 3 7. 000000 + 3. 00000 = 10. 000000 7. 000000 - 3. 00000 = 4. 000000 7. 000000 * 3. 00000 = 21. 000000 7. 000000 / 3. 00000 = 2. 333333
פורמטים שונים – קליטה והדפסה #include <stdio. h> int main () { char c 1, c 2, c 3; int i; float x; double y; printf("Input three charactersn an int, a float, and a double: n "); scanf("%c%c%c%d%f%lf", &c 1, &c 2, &c 3, &i, &x, &y); printf("n. Here is the data that you typed in: n"); printf("%3 c%3 c%3 c%5 d%17 gnn", c 1, c 2, c 3, i, x, y); return 0; }
פלט Input three characters an int, a float, and a double: • Abc 4 3. 4 4. 7 • Here is the data that you typed in: A b c 4 3. 4 4. 7 •
C- תרגום ל #include <stdio. h> int main() { int min, a, b; scanf(“%d%d”, &a, &b); min = a; if (min > b) min = b; printf(“The min is %dn”, min); return 0; }
תוכנית המוצאת את החזקה - דוגמא . 1000 אשר גדולה מ 2 הראשונה של #include <stdio. h> int main() { int product = 2; while (product <= 1000) product = product * 2; printf (“The minimal number is %dn”, product); return 0; }
מספרים 10 תוכנית הקולטת : 2 דוגמא ומחשבת את הממוצע שלהם int main() { int counter, grade, total; float average; total = 0; counter =1; while (counter <= 10) { הגדרת משתנים printf(“Enter grade: n”); scanf(“%d”, &grade); total = total + grade; counter = counter + 1; } average = total / 10. 0; printf(“The average %fn”, average); return 0; } שלב האתחול שלב העיבוד
- Slides: 32