array of integer in C
Hi everyone
I have some problems with an array of integer numbers. let's suppose we have an array v[]= {2,3,0,5,0,7,0,0,0,11,0,13,0,0,0,17,0,19} from this array I'd like to get a second array q[]={1,1,3,1,3,1} where the number in this array are the total number of zeros between two prime numbers. any idea would be great. thank you very much in advance. PS: my coding skills are a bit rusty |
I suppose you could have a loop that ran through the big array sequentially, testing each value against zero and storing the result in a counter that is zeroed after every non-zero value in the array. Like in this pseudocode
Code:
while items in array |
Quote:
I call the most lengthy process, brute force. Since your requirement is something stated, and you've demonstrated an example. Apply logic leading to an algorithm towards that example. Then create examples where there should be different outcomes as well as non-conditions which should not be detected. Go from the first element of that primary array, one element at a time, and evaluate it. What will you need to remember?
|
as usual, we would like to see your code and where did you stuck
we can definitely help you to continue, but I think it is your homework (and not mine). |
Every number in the question you posted is prime.
Do you need to determine if each number is prime, or can you just assume they all are? |
i typically prototype more complicated programs, using simpler test cases, in higher level languages such as Pike or Python (use whatever works best for you) before i code up a C version to really kick some ... cores. in some cases i have found the higher level version good enough for my needs. but if you are trying to build your experience in C, then you need to stick with that. but prototyping is still a useful methodology.
|
thank you very much to all of you for the reply, most of the time thanks to members of this community, make my life easy.
please believe me that was not my intention to get someone to write the code for me. often reply like "try to do this or that" or even "get out of that wardrobe and get some air" solve my mathematical problems. i have to admit my skills in that area is not that good either. i d like also to say that i like to share codes, maybe someone somewhere work on the same problem. so here the code (please only if you are interested). Code:
#include <stdio.h> |
Quote:
Quote:
Quote:
Quote:
|
thank you very much again.
i just finish working on a separate code to solve my problem, i'll post this new code. this code generate an array without zeros and without repetitions of numbers (each elements appear only once), at the moment i m out of the wardrobe to get same fresh air but as soon as i can I will get inside again to try to implement this second code in my original one. thanks again to all of you. sorry no time to translate my writing in English inside the code, but is quite simple. here is the code Code:
#include <stdio.h> |
is this the original formatting of your file? Would be nice to have a better one.
Code:
#include <stdio.h> |
Are there further questions?
|
Thank you for the web site for better format coding, and no at the moment I don't have anything else to ask, but is a work in progress and I m sure something else will come along the way.
Thanks again. |
There's a program called clang-format, which you can use to automatically format C code. It's fairly standard these days.
|
There's also an old-school one called 'indent'
I wasn't aware of the clang one. Might have to see if I can find a Allman style config file for it. |
thanks for the additional information.
|
All times are GMT -5. The time now is 01:33 AM. |