include stdio h include math h void main

  • Slides: 33
Download presentation

#include <stdio. h> #include <math. h> void main() { double number, square_power; printf(“Enter a

#include <stdio. h> #include <math. h> void main() { double number, square_power; printf(“Enter a real number: ”); scanf(“%d”, &number); square_power = pow(number, 2); printf(“The square power of %e is %en”, number, square_power); } 14/2/2000 Εκλεπτυνση/Υλοποιηση epl-131 5

Αφαιρετικότητα Συνάρτησης #include <stdio. h> #include <math. h> void main() { double number, square_power;

Αφαιρετικότητα Συνάρτησης #include <stdio. h> #include <math. h> void main() { double number, square_power; printf(“Enter a real number: ”); scanf(“%d”, &number); square_power = pow(number, 2); printf(“The square power of %e is %en”, number, square_power); } printf, scanf, pow ξερουμε τι κανουν οχι πως 14/2/2000 epl-131 6

Συνάρτηση main χωρις παραμετρους void main() { printf(“Hello out there!n”); } 14/2/2000 epl-131 11

Συνάρτηση main χωρις παραμετρους void main() { printf(“Hello out there!n”); } 14/2/2000 epl-131 11

Συνάρτηση χωρις παραμετρους void display_six_stars() { printf(“******n”); } void display_six_stars() { printf(“******n”); return; }

Συνάρτηση χωρις παραμετρους void display_six_stars() { printf(“******n”); } void display_six_stars() { printf(“******n”); return; } 14/2/2000 epl-131 12

#include <stdio. h> void display_six_stars() { printf(“******n”); } int main() { display_six_stars(); return 0;

#include <stdio. h> void display_six_stars() { printf(“******n”); } int main() { display_six_stars(); return 0; } 14/2/2000 epl-131 επιστροφη κληση 13

Συναρτήσεις με Μια Παραμετρο χωρις τιμη εξοδου void display_area(float area) { printf(“The area is

Συναρτήσεις με Μια Παραμετρο χωρις τιμη εξοδου void display_area(float area) { printf(“The area is %f square metersn”, area); } 14/2/2000 epl-131 15

Συναρτήσεις με Μια Παραμετρο χωρις τιμη εξοδου void compute_and_display_mod 3(int number) { printf(“%dmod 3

Συναρτήσεις με Μια Παραμετρο χωρις τιμη εξοδου void compute_and_display_mod 3(int number) { printf(“%dmod 3 is %dn”, number%3); } void compute_and_display_mod 3(int number) { int mod 3; mod 3 = number%3; printf(“%dmod 3 is %dn”, number, mod 3); } 14/2/2000 epl-131 16

Συνάρτηση με πολλαπλές παραμέτρους χωρίς τιμή εξοδου void display_area(float length, float width, float area)

Συνάρτηση με πολλαπλές παραμέτρους χωρίς τιμή εξοδου void display_area(float length, float width, float area) { printf(“The area of a rectangle with length %f m and width %f m is %f sq. mn”, length, width, area); } 14/2/2000 epl-131 17

#include <stdio. h> float compute_area(float x, float y); πρωτοτυπο συναρτησης { ορισμος συναρτησης τυπικοι

#include <stdio. h> float compute_area(float x, float y); πρωτοτυπο συναρτησης { ορισμος συναρτησης τυπικοι παραμετροι float compute_area(float a, float b) return (a * b); } int main() { float length, width; float area; ορισματα/ πραγματικοι παραμετροι 14/2/2000 printf(“Enter length and width: “); scanf(“%f%f”, &length, &width); area = compute_area(length, width); κληση συναρτησης printf(“The area of a rectangle with dim %f by %f m is %f sq. mn”, length, width, area); return(0); epl-131 23 }

Προτώτυπα Συναρτήσεων /* σχολια */ /* #include */ /* προτωτυπα συναρτησεων */ float compute_area(float

Προτώτυπα Συναρτήσεων /* σχολια */ /* #include */ /* προτωτυπα συναρτησεων */ float compute_area(float length, float width); void error_message_for_negative_input(); int get_grade(int student_id); /* σταθερες*/ /* ορισμος συναρτησεων - μια ειναι η main*/ 14/2/2000 epl-131 25

#include <stdio. h> int compute_sum(int x, int y); πρωτοτυπο συναρτησης { ορισμος συναρτησης τυπικοι

#include <stdio. h> int compute_sum(int x, int y); πρωτοτυπο συναρτησης { ορισμος συναρτησης τυπικοι παραμετροι int compute_sum(int a, int b) int sum; sum = a + b; return sum; } Ορισματα/ πραγματικοι παραμετροι int main() { int sum=0; sum = compute_sum(5, 4); κληση συναρτησης printf(“The sum of %d and %d is %dn”, 4, 5, sum); return(0); } 14/2/2000 epl-131 26

#include <stdio. h> int compute_sum(int x, int y); int compute_sum(int a, int b) {

#include <stdio. h> int compute_sum(int x, int y); int compute_sum(int a, int b) { int sum; sum = a + b; return sum; } int main() { int sum=0; sum = compute_sum(5, 4); printf(“The sum of %d and %d is %dn”, 4, 5, sum); return(0); } 14/2/2000 epl-131 27

#include <stdio. h> int compute_sum(int x, int y); int compute_sum(int a, int b) {

#include <stdio. h> int compute_sum(int x, int y); int compute_sum(int a, int b) { int sum; sum = a + b; return sum; } int main() { int sum=0; sum 09 a 5 b sum = compute_sum(5, 4); sum 4 9 printf(“The sum of %d and %d is %dn”, 4, 5, sum); return(0); } 14/2/2000 epl-131 28

#include <stdio. h> int compute_sum(int x, int y); sum int compute_sum(int a, int b)

#include <stdio. h> int compute_sum(int x, int y); sum int compute_sum(int a, int b) { int sum; sum = a + b; return sum; } 9 int main() { int sum=0; sum = compute_sum(5, 4); printf(“The sum of %d and %d is %dn”, 4, 5, sum); return(0); } 14/2/2000 epl-131 29

#include <stdio. h> int compute_sum(int x, int y); void compute_sum(int a, int b) {

#include <stdio. h> int compute_sum(int x, int y); void compute_sum(int a, int b) { int sum; sum = a + b; return sum; } int main() { int sum=0; int a=4, c=6; sum = compute_sum(a, c); sum 0 a 4 c 6 a 4 b 6 printf(“The sum of %d and %d is %dn”, a, c, sum); return(0); sum } 14/2/2000 epl-131 30

void display_time(int time) { /* compute hours */ /* compute minutes */ /* display

void display_time(int time) { /* compute hours */ /* compute minutes */ /* display hours: minutes } void display_time(int time) { int hours, minutes /* compute hours */ hours = time / 100; /* compute minutes */ minutes = time % 100; /* display hours: minutes printf(“The time is %02 d: %02 dn”, hours, minutes); }