0
h. Ask the user for the amount of terms he wants and print the sequence below and the sum of terms. 1 + 1 + 2 + 3 + 5 + 8 +… 2 3 5 7 11 13 * above Fibonacci sequence and below Primes sequence.
I have this exercise to do, but I’m not getting it. When I play the two together, it changes everything. But if I do it separately, I can do the sequence perfectly.
How to solve?
My code so far: http://pastebin.com/ChG2VDTv
#include "stdio.h"
main(){
int qtd, n1=0, n2=1, f=0, p=2, cont=0, j;
int a = 0;
printf("Entre com a quantidade de termos: ");
scanf("%d", &qtd);
for(int i=0; i<=qtd; i++){
cont=0;
for(j=1; j<=i; j++){
if (i%j==0){
cont++;
}
}
if(i!=0){
if(cont==2){
//printf("%d ", i);
printf("%d/%d + ", f, i);
}
}
/*if(i!=0){
printf("%d + ", f);
}*/
n1 = n2;
n2 = f;
f = n1+n2;
}
return 0;
}
It would be interesting to show working separately. In thesis has no secret to join. Unless I don’t understand something, you make one list and then you make the other, so it shouldn’t be hard to do together.
– Maniero
@Michael, I reversed the issue. This is not a forum, and you don’t change the question to [solved]. You can post your solution as a reply and mark as accepted, or if any of the answers answered, just mark the respective answer as accepted (it’s the green V right under the answer score): Here are some cool things to understand the functioning of the site: [help] and Community FAQ.
– Bacco