CourseNotes C

download CourseNotes C

If you can't read please download the document

description

xvx

Transcript of CourseNotes C

project C, , , printf, scanf

Project C C++ Microsoft Visual Studio 20051. File -> New -> Project :Project Type: Win32Template:Win32 Console Application

, (location) project create directory for solution.

2. Next Console Application Empty Project .

3. Finish project .

4. (source file) project Source Files Solution Explorer .

5. Add->New Item Code Categories . Add .

1 project f1e1 :#include

void main() {

int a;

a = 12;

printf("Kalimera ! \n "); printf("H timi ths metabliths a einai : [ %d ]", a );

}

. ;

2

a b

3

printf ( /* .. */ // ) . ?

4

project f1e4 4 :

// //

#include

void main() {

int a;float b; char c; double d;

a = 12;b = 1.2345678901234567890;c = 'A';d = 1.2345678901234567890;

printf("\n H timi tis a einai: %d",a);

printf("\n H timi tis b einai: %f",b); printf("\n H timi tis b einai: %5.2f",b); printf("\n H timi tis b einai: %.3f",b); printf("\n H timi tis b einai: %.40f",b);printf("\n H timi tis c einai: %c",c); printf("\n H timi tis d einai: %.40lf \n",d);}

. printf (\n, %d, %f, %c, %lf ) ?

5 project f1e5 :

#include

void main() {

int a ;

printf("Kalimera ! \n ");

printf(\n Dwse timi :); scanf(%a, &a );

printf("H timi ths metabliths a einai : [ %d ]", a );

}

. ;

6

float.

7

int , , , .

8

C .

#define.

(if), , (switch)

1

project f2e1 :

#include

void main() {

int arithmitis,paronomastis; int ypolipo, piliko;

printf("Dwse dieraiaio kai diaireti: \n "); scanf(%d%d, &arithmitis, &paronomastis);

if(paronomastis != 0 ) { piliko = arithmitis / paronomastis; ypolipo = arithmitis % paronomastis; printf("To Piliko einai: %d\n ", piliko); printf("To Ypoloipo einai: %d\n ", ypolipo); } else { printf("H diairesi me to 0 einai adunath\n"); }}

. ;

2

project f2e2 5. , .

3

#include

void main() {

int age ;

printf("Dwse thn hlikia sou: \n "); scanf(%d, & age );

if( (age > 0) && (age < 18) ) { printf("Eisai polu neos, h hlikia sou einai: %d\n ", age ); } else if ( (age >= 18) && (age 61) && (age < 110) ) { printf("Eisai geros, h hlikia sou einai: %d\n", age ); } else { printf("O arithmos %d den einai apodektos ws hlikia\n ", age ); }

}

. . ; ?

. , 60 18

. &&

||

!

4

project f2e4 , 1., 2.,3.,4.. , . 2,5 , 2 , 3 , 3 .

5

project f2e5 3 .

6

project f1e6 :#include

void main() {

int epilogi; float a, b; printf(1.Prosthesi\n2.Aferaisi\nTi epilegeis?); scanf(%d, &epilogi ); printf(Dwse 2 pragmatikous arithmous gia na pragmatopoihsw thn praksi:); scanf(%f%f, &a, &b); switch(epilogi) { case 1: apot = a + b; printf("To athroiisma einai : %d\n", apot ); break; case 2: apot = a - b; printf("To athroiisma einai : %d\n", apot ); break; default: printf("Lathos Epilogi\n"); break; }}

. ;

6

.

7

. a.prosthesi b.aferaisi c.pollaplasiasmo d.diairesi

8

4, switch

9

if switch?if

switch

10 . ( ) 20 0,5020 30 1,230 40 2,4 40 3,5 60 .

project f2e10 .

(for, while, do-while)

1

project f3e1 : A#include

void main() {

printf("Eimai h grammh 1\n "); printf("Eimai h grammh 2\n "); printf("Eimai h grammh 3\n "); printf("Eimai h grammh 4\n "); printf("Eimai h grammh 5\n "); printf("Eimai h grammh 6\n "); printf("Eimai h grammh 7\n "); printf("Eimai h grammh 8\n "); printf("Eimai h grammh 9\n "); printf("Eimai h grammh 10\n "); printf("Eimai h grammh 11\n "); printf("Eimai h grammh 12\n "); printf("Eimai h grammh 13\n "); printf("Eimai h grammh 14\n "); printf("Eimai h grammh 15\n "); printf("Eimai h grammh 16\n "); printf("Eimai h grammh 17\n "); printf("Eimai h grammh 18\n "); printf("Eimai h grammh 19\n "); printf("Eimai h grammh 20\n "); }

#include

void main() {

int i;

for(i=1; i