Download presentation

Presentation is loading. Please wait.

Published byMax Wile Modified over 3 years ago

1
We Have Learned main() { … } Variable –Definition –Calculation –Display We can do some real programming! –Think about your solution design –Express design in Pseudocode (in between C and English) –Code your design into C

2
Example: Calculate Function Values Problem: Suppose y = (x-1) 2 +10. What value will y be when x = 10? Your main code: x = 10; y = (x-1)*(x-1)+10; C code #include int main() { int x, y; x = 10; y = (x-1)*(x-1) + 10; printf("The result is: %i\n", y); return 0; }

3
scanf Get user input from the keyboard –Same format as printf, except put “&” in front of variable names scanf(“%i”, &count); –“&” means the "address of“ to store whatever the user enters into the memory address (location) of the variable Leaving out the & will cause your program to work incorrectly! And indeterminately!

4
Example #include int main() { int x, y; printf("What is the value for x? \n"); scanf("%i", &x); y = (x-1)*(x-1) + 10; printf("The result is: %i\n", y); return 0; }

5
Fibonacci number Sequence 1, 1, 2, 3, 5, 8, … Speed rabbits could breed in ideal circumstances –Start with a newly-born pair of rabbits –At the end of their second month a female can produce another pair of rabbits –Rabbits never die –Female always produces one new pair (one male, one female) every month from the second month Let F(n) mean "the number of pairs of rabbits at the start of the n-th month"

6
Fibonacci number

7
Calculate Fibonacci number int main() { int f0, f1, f2, f3, f4, f5; f0 = 0; f1 = 1; f2 = f0 + f1; f3 = f1 + f2; f4 = f2 + f3; f5 = f3 + f4; printf("%i %i %i %i %i\n", f1, f2, f3, f4, f5); return 0; }

8
Calculate Fibonacci number – cont. #include int main() { int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10; f1 = 1; f2 = 1; f3 = f1 + f2; f4 = f2 + f3; f5 = f3 + f4; f6 = f4 + f5; f7 = f5 + f6; f8 = f6 + f7; f9 = f7 + f8; f10 = f8 + f9; printf("%i %i %i %i %i %i %i %i %i %i\n", f1, f2, f3, f4, f5, f6, f7, f8, f9, f10); return 0; }

Similar presentations

OK

Waiters’ Nightmare A single rectangular table can seat 6 hungry humans.

Waiters’ Nightmare A single rectangular table can seat 6 hungry humans.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google

Ppt on decimals for class 4 Ppt on apple ipad Ppt on current environmental issues Ppt on origin of earth Cell surface display ppt on tv Ppt on class 10 hindi chapters Ppt on meaning and importance of communication Ppt on introduction to object oriented programming Ppt on 5 star chocolate desserts Ppt on area of plane figures