Translate

giovedì 5 febbraio 2015

CERCA POSITION DI UN NUMERO

#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <time.h>

int main()
{
 int numcella = 0;                                
 printf("digita numero dim (max 100) : ");              /// dimensione del vett/////
 scanf("%d",&numcella);                         


 int numero[500];              /// numero max

 srand(time(NULL));             ///rand


 for (int i = 0; i < numcella; i++) {                   ///////////////////////////////
  numero[i] = rand() % 100 + 1;                       ////// carica e visualiza/////
  printf("[%d]%d \n", i, numero[i]);                 //////////////////////////////
  }
 
 
 printf("_______________________________________________________________________\n");

 int puesto;                                       ////////////////////////////////////
 printf("digita un numero: ");                     ////// numero, cerca pisition////
 scanf("%d", &puesto);                             //////////////////////////////////

 printf("_______________________________________________________________________\n");


int apogio=0;                                             ////////////////////////////////          
for (int i = 0; i <numcella; i++){                        ////////////////////////////////
if (puesto==numero[i]){                                   //////CERCA POSITION DI NUMERO///
 printf ("il numero e nella posizione %d \n",i);       ////////////////////////////////
 apogio=1; //////// SERVE PER IF DOPO IL CICLO         //////////////////////////////////
}
}



if(apogio==0){                                             ///////////////////////////////////////
 printf ("il numero non e' stato trovato\n");           ////// TRU O FALSE ////DOPO IL CICLO///
}                                                          ////////////////////////////////////////

 system ("pause");
 return 0;
}

Nessun commento:

Posta un commento