Computer Programming Summer 2016 1 1 offset mins

  • Slides: 29
Download presentation
Computer Programming Summer 2016 1 תרגול 1

Computer Programming Summer 2016 1 תרגול 1

 פיתרון offset , mins , hour קלוט. 1 mins + offset total. Min.

פיתרון offset , mins , hour קלוט. 1 mins + offset total. Min. 2 (hour + total. Min / 60) % 24 hour. 3 total. Min % 60 mins. 4 hour : : mins הדפס. 5 נבדוק נכונות האלגוריתם 8

9

9

2 שאלה num 1>num 2>num 3 : נניח שאנו רוצים לקבל num 1 ?

2 שאלה num 1>num 2>num 3 : נניח שאנו רוצים לקבל num 1 ? num 2 num 1 ? num 3 num 2 ? num 3 : מצב התחלתי num 1 > num 2 num 1 ? num 3 num 2 ? num 3 num 1 > num 2 num 1 > num 3 num 2 > num 3 : מצב סופי

2 שאלה #include <stdio. h> int main() { int num 1, num 2, num

2 שאלה #include <stdio. h> int main() { int num 1, num 2, num 3; //These are the numbers that will be sorted. int temp; //This is a variable that will be used for swapping. printf("Please enter three integers: n"); scanf("%d %d %d", &num 1 , &num 2 , &num 3); if(num 1 < num 2) { //Swap between num 1 and num 2 so that num 1 will //hold the larger value: temp=num 1; num 1 > num 2 num 1=num 2; num 1 ? num 3 num 2=temp; num 2 ? num 3 }

2 שאלה } if(num 1 < num 3) { //Swap between num 1 and

2 שאלה } if(num 1 < num 3) { //Swap between num 1 and num 3 so that num 1 will hold the //larger value: num 1 > num 2 num 1 > num 3 temp=num 1; num 2 ? num 3 num 1=num 3; num 3=temp; } if(num 2 < num 3) { //Swap between num 2 and num 3 so that num 2 will hold the //larger value: num 1 > num 2 num 1 > num 3 temp=num 2; num 2 > num 3 num 2=num 3; num 3=temp; } printf("The numbers in increasing order are: %d, %d and %d. n", num 3, num 2, num 1);

4 שאלה #include <stdio. h> #include <stdlib. h> void main() { int n, Fn

4 שאלה #include <stdio. h> #include <stdlib. h> void main() { int n, Fn 1, Fn 2, i; printf(" N = "); scanf("%d", &n) ; Fn 2 = 0 ; Fn 1 = 1 ; Fn = n ; } for (i=2 ; i <= n ; i++){ Fn = Fn 1 + Fn 2; Fn 2 = Fn 1; Fn 1 = Fn; } printf("F(%d) = %d n", n, Fn);

5 פיתרון שאלה . denom 1. 1 sign 1. 2 . pi DELTA 0.

5 פיתרון שאלה . denom 1. 1 sign 1. 2 . pi DELTA 0. 0. 3 0. 0001. 4 בצע. 5 next pi 1. 0 / denom 5. 1 pi + sign*next 5. 2 denom sign denom + 2 5. 3 sign*(-1) 5. 4 (next>(DELTA/4)) כל עוד 5. 5 . (denom-1)/2 ואת pi*4 הדפס את. 6 24

5 שאלה #include <stdio. h> #define DELTA 0. 0001 void main() { int denom=1,

5 שאלה #include <stdio. h> #define DELTA 0. 0001 void main() { int denom=1, sign=1; float pi=0. 0, next; do { next = 1. 0 / denom; pi += sign * next; denom+= 2; sign *= -1; } while (next > (DELTA/4)); } printf("PI=%f #members=%d n", pi*4, (denom-1)/2);

6 שאלה #include <stdio. h> void main() { int grade; printf("Enter graden"); scanf("%d", &grade);

6 שאלה #include <stdio. h> void main() { int grade; printf("Enter graden"); scanf("%d", &grade); if (grade<56){ printf("failedn"); } else{ if ((grade>=56) && (grade<=79)){ printf("passedn"); } else{ printf("good graden"); } } }