Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Escribir una funcion que devuelva el numero de valores positivos
- y negativos del fichero datos.txt, completando este main:
- #include <stdio.h>
- int main(){
- int npos, nneg;
- // AQUI LA LLAMADA A LA FUNCION
- printf("Hay %d positivos y %d negativos",npos,nneg);
- return 0;
- } */
- #include <stdio.h>
- #include <stdlib.h>
- int posneg( int *p, int *n ){
- FILE *f_in;
- int num;
- f_in=fopen("datos.txt","r");
- if( f_in==NULL ) printf(" No se encuentra el archivo \n ");
- else{ p=0; n=0;
- while( fscanf(f_in,"%f",&num) != EOF ){
- if( num>0 ) *p++; // if( num%2==0) para pares
- if( num<0 ) *n++; // if( num%2!=0) para impares
- }
- fclose(f_in);
- }
- }
- int main (){
- int npos, nneg;
- posneg(&npos,&nneg);
- printf(" Hay %d positivos y %d negativos \n ",npos,nneg);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement