Primeros pasos en C

Anuncio
¿Qué editor de texto usar?
gEdit.
vim.
emacs.
SublimeText.
Nano.
Primeros pasos en C
# include < stdio .h >
int main ( int argc , char * argv []) {
printf ( " Hola mundo !\ n " ) ;
return 0;
}
Como compilarlo?
$ cc ex0 . c -o ex0
$ ./ ex0
Hola mundo !
$
Primeros pasos en C
# include < stdio .h >
int main ( int argc , char * argv []) {
printf ( " Hola " ) ;
printf ( " mundo " ) ;
printf ( " !\ n " ) ;
return 0;
}
Primeros pasos en C
0
20
40
60
80
100
120
140
160
180
200
220
240
260
280
300
-17
-6
4
15
26
37
48
60
71
82
93
104
115
126
137
148
Primeros pasos en C
# include < stdio .h >
int main () {
int fahr , celsius ;
int lower , upper , step ;
lower = 0;
upper = 300;
step = 20;
fahr = lower ;
while ( fahr <= upper ) {
celsius = 5 * ( fahr - 32) / 9;
printf ( " % d \ t % d \ n " , fahr , celsius ) ;
fahr = fahr + step ;
}
return 0;
}
Primeros pasos en C
# include < stdio .h >
int main () {
int fahr ;
for ( fahr =0; fahr <=300; fahr = fahr +20) {
printf ( " % d \ t % d \ n " , fahr , 5*( fahr -32) /9) ;
}
return 0;
}
Primeros pasos en C
# include < stdio .h >
# define LOWER 0
# define UPPER 300
# define STEP 20
int main () {
int fahr ;
for ( fahr = LOWER ; fahr <= UPPER ; fahr = fahr +
STEP ) {
printf ( " % d \ t % d \ n " , fahr , 5*( fahr -32) /9) ;
}
return 0;
}
Primeros pasos en C
# include < stdio .h >
int main () { // primer intento
int c ;
c = getchar () ;
while ( c != EOF ) {
putchar ( c ) ;
c = getchar () ;
}
}
Primeros pasos en C
# include < stdio .h >
int main () { // segundo intento
int c ;
while (( c = getchar () ) != EOF )
putchar ( c ) ;
return 0;
}
Primeros pasos en C
# include < stdio .h >
// cuenta los caracteres de la entrada
int main () {
int c , nc ;
nc = 0;
while (( c = getchar () ) != EOF )
++ nc ;
printf ( " % d \ n " , nc ) ;
return 0;
}
Primeros pasos en C
# include < stdio .h >
// cuenta las lineas de la entrada
int main () {
int c , nl ;
nl = 0;
while (( c = getchar () ) != EOF )
if ( c == ’\ n ’)
++ nl ;
printf ( " % d \ n " , nl ) ;
return 0;
}
Primeros pasos en C
# include < stdio .h >
# define IN 1
# define OUT 0
// cuenta todo ! ;)
int main () {
int c , nl , nw , nc , state ;
state = OUT ;
nl = nw = nc = 0;
[[ alto while ]]
printf ( " % d % d % d \ n " , nl , nw , nc ) ;
}
Primeros pasos en C
while (( c = getchar () ) != EOF ) {
++ nc ;
if ( c == ’\ n ’)
++ nl ;
if ( c == ’ ’ || c == ’\ n ’ || c == ’\ t ’)
state = OUT ;
else if ( state == OUT ) {
state = IN ;
++ nw ;
}
}
Primeros pasos en C
Descargar