include stdio h int main void Define variables
#include <stdio. h> int main (void) { // Define variables double a, b, c; printf("n Hello!"); printf("n Give me a = "); scanf("%lf", &a) ; printf("n Give me b = "); scanf("%lf", &b) ; c = a+b; printf("n The sum is c = %lf", c); printf("n The sum with 7 total digits and 3 decimal digits is c = %7. 31 f", c); printf("n The sum written scientifically is c = %en", c) ; return 0; }
Ανάλογα με το προϊόν και ειδικότερα για παλιότερες εκδόσεις μπορεί να χρειασθούν προσθήκες στο πρόγραμμά μας για να βλέπουμε τα αποτελέσματα πχ. #include <iomanip. h> #include <stdio. h> #include <iomanip. h> int main (void) { // Define variables double a, b, c; printf("n Hello!"); printf("n Give me a = "); scanf("%lf", &a) ; printf("n Give me b = "); scanf("%lf", &b) ; c = a+b; printf("n The sum is c = %lf", c); printf("n The sum with 7 total digits and 3 decimal digits is c = %7. 31 f", c); printf("n The sum written scientifically is c = %en", c) ; system("pause"); return 0; }
#include <stdio. h> int main(void) // calculate 2*pi*r { // Define variables float r=2. 5; float t; float pi=3. 14; t=2*pi*r; printf("aktina r= %5. 2 f m n", r); printf("mhkos perifereias kuklou aktinas t= %5. 2 f m n", t); printf("mhkos perifereias kuklou aktinas t= %7. 3 f m n", t); return 0; }
#include <stdio. h> int main(void) // read 3 numbers, calculate sum and average { // Define variables float sum, average, x 1, x 2, x 3; printf("give 3 numbers n"); scanf("%f %f %f", &x 1, &x 2, &x 3); printf("print the 3 numbersn"); printf("%5. 3 fn", x 1, x 2, x 3); sum=x 1+x 2+x 3; average=sum/3. 0; printf("sum=: %5. 3 f n", sum); printf("average=: %5. 3 f n", average); return 0; }
#include <stdio. h> #include <math. h> int main(void) // solve equation { // Define variables double a, b, c, d, xl, x 2; printf("n. Give value a (non-zero)"); scanf("%lf", &a) ; printf("n. Give value b ") ; scanf("%lf", &b) ; printf("n Give value of c ") ; scanf("%lf", &c) ; d=b*b-4*a*c; if (d==0. 0) { xl = -0. 5*b/a; printf("n. The double root is x= %f ", xl); printf("n "); } else { if (d<0) { printf("n No real roots "); printf("n "); } else { xl=0. 5*(-b+sqrt(d))/a; x 2=0. 5*(-b-sqrt(d))/a; printf("n. The two roots are xl= %f and x 2=%f", xl, x 2); printf("n "); } } return 0; }
#include <iostream> int main() { std: : cout<<"Hello World!n"; return 0; } #include <iostream> cin cout
#include <iostream> #include <iomanip> int main() { std: : cout<<std: : setw(60)<<"Programmer: Student "<<std: : endl; std: : cout<<std: : setw(60)<<"if. . . else "<<std: : endl; int i; std: : cout<<"give me a number "; std: : cin>>i; if(i==0) std: : cout<<"number is 0 "<<std: : endl; else if (i>0) { std: : cout<<"positive number"<<std: : endl; if (i>10) std: : cout<<i<<" > 10"<<std: : endl; else if (i==10) std: : cout<<"einai iso me to 10 "<<std: : endl; else std: : cout<<i<<" < 10"; } else std: : cout<<"negative number"<<std: : endl; return 0; }
#include <stdio. h> int main (void) { printf("typwse tis vasikes diastaseis (se bytes) twn typwn ths C : nn"); printf(" char: %3 d byte(s)n", sizeof(char)); printf(" short: %3 d byte(s)n", sizeof(short)); printf(" int: %3 d byte(s)n", sizeof(int)); printf(" unsigned: %3 d byte(s)n", sizeof(unsigned)); printf(" long: %3 d byte(s)n", sizeof(long)); printf(" float: %3 d byte(s)n", sizeof(float)); printf(" double: %3 d byte(s)n", sizeof(double)); printf(" long double: %3 d byte(s)n", sizeof(long double)); return 0; }
#include <stdio. h> int main(void) { printf(" Metatropi Arithmwn apo to ena sistima sto allo nn"); printf("D = Decimal - H = Hexadecimal - O = Octadecimaln"); printf("D - H - On"); printf("%d %x %on", 19, 19); printf("H - D - On"); printf("%x %d %on", 0 x 15, 0 x 15); printf("O - H - Dn"); printf("%o %x %dn", 012, 012); return 0; }
- Slides: 12