LinuxQuestions.org [SOLVED] array of integer in C new problem
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 08-24-2019, 07:04 AM #1 sibelius Member   Registered: Oct 2018 Location: Leura NSW Australia Distribution: Linux Knoppix 8.1 Posts: 53 Rep: array of integer in C new problem hi everybody this time i am stuck on the following problem: let's suppose i have an array[2,3,5,7] and a certain number n. my goal is to create a new array in the following way. the integer n divide array[0] till some condition is true; if false n start to divide array[1] till the same condition is true........ if false n divide array[3] (last component) till the same condition is true. all the time the condition is not verify, before the cycle goes to the next step i need to count the number of division. in the end in the new array I'd like to see integers which one represent the number of division while the condition impose is true. thank you in advance for any suggestion. my wrong pseudo code Code: ```for(i=0; i
 08-24-2019, 07:53 AM #2 NevemTeve Senior Member   Registered: Oct 2011 Location: Budapest Distribution: Debian/GNU/Linux, AIX Posts: 3,844 Rep: Perhaps something like this: Code: ```for(i=0; i
 08-25-2019, 11:05 PM #3 sibelius Member   Registered: Oct 2018 Location: Leura NSW Australia Distribution: Linux Knoppix 8.1 Posts: 53 Original Poster Rep: Thank you, I 'll try your way. Thanks again
 08-27-2019, 05:14 PM #4 sibelius Member   Registered: Oct 2018 Location: Leura NSW Australia Distribution: Linux Knoppix 8.1 Posts: 53 Original Poster Rep: thank you very much again for your help NevemTeve, I solve the problem and I post the solution. Code: ```for(i=0;i #define N 5000 int insert(int *v) { int i, n; printf("controlliamo se n e' >= 2 e in tal caso procediamo\n"); printf("2 e' l unico numero primo pari, per controllare se n e' primo basta vedere se nella colonna dei numeri primi generati\n"); printf("l ultimo numero coincide con n, se coincide il numero e' primo altrimenti non lo e'\n"); printf("controlliamo se n e' pari o dispari\n"); printf("troviamo i numeri primi <= di n con il Crivello di Eratostene\n"); printf("attenzione se inserisci un numero con il punto o con la virgola il codice\n"); printf("va in loop e per fermarlo occorre premere ctrl+c e ricompilarlo per ripartire\n\n\n\n"); while (n<2) { printf("il numero deve essere >=2, per favore inseriscilo qui:"); scanf("%d", &n); } if (n%2 == 0) printf("il numero e' positivo e pari\n"); else printf("il numero e' positivo e dispari\n"); printf("\n"); /*generiamo un vettore di zeri*/ for(i=2; i<=n; i++) v[i]=0; return n; } void eratostene(int *v, int n) { int i,j; for(i=2; i<=n; i++) if(v[i]==0) for(j=2*i; j<=n; j+=i) v[j]=1; //let's set v[j]=1, to mark all the multiple number ; that's the sieve } void print(int *v, int n) { int i,k; k=0; for(i=2; i<=n; i++) if(v[i]==0) //if the number is prime k=k+1; //count the number of prime numbers printf("\nnumeri primi compresi tra 2 e %d sono %d:\n\n",n,k); } int primo (int *v, int *q,int n) {//memorizzo i primi nel vettore q[i] ma contiene anche gli zeri int i,j; for(i=2; i<=n; i++) if(v[i]==0) q[i]=i; //vettore che contiene i numeri primi e gli zeri come distanze } int terzo (int *q,int *z,int n) { //creo un nuovo vettore di primi senza gli zeri int i,j,M,flag; M=0; //dimensione nuovo vettore for(i=2; i<=n; i++) if(q[i]!=0) { flag=0; for(j=0;j<=M ;j++) if(z[j]==q[i]) flag=1; if(flag==0) z[M]=q[i]; M=M+1; }//chisura ciclo if printf("numeri primi memorizzati in un vettore\n"); //ho eliminato gli zeri da q nel vettore z for(i=0; i

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post calvarado777 Programming 8 07-26-2013 09:48 PM Basel Programming 5 10-27-2010 12:35 PM syseeker Programming 2 06-27-2006 03:33 AM appas Programming 11 11-23-2004 01:56 PM jetfreggel Programming 3 12-29-2002 08:39 AM

LinuxQuestions.org

All times are GMT -5. The time now is 06:53 PM.