Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 100
- int prim ( int v[], int busq ){
- int i;
- for( i=0 ; i<N ; i++ )
- if ( v[i]==busq ){
- printf(" La primera posición es %d \n ",i);
- return i;
- }
- printf(" Valor no encontrado \n ");
- return -1;
- }
- int last( int v[] , int busq){
- int i;
- for( i=N ; i>=0 ; i-- )
- if ( v[i]==busq ){
- printf(" La ultima posición es %d \n ",i);
- return i;
- }
- void todo( int v[] ){
- int i;
- printf(" Posiciones: ");
- for( i=0 ; i<N ; i++ )
- if ( v[i]==busq ){
- printf(" %d ",i);
- printf(" \n ");
- }
- int main(){
- FILE *f_in=fopen("datos.txt");;
- int v[N], i, busq;
- while ( fscanf(f_in,"%d ",&v[i]) != EOF ) i++;
- printf(" \n Dime que valor buscas: ");
- scanf("%d ",&busq);
- prim(v,busq);
- if( prim(v,busq) != -1){
- last(v,busq);
- todo(v,busq);
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement