Sequence of fraction with fibonacci and primes

0

h. Ask the user how many terms he wants and print out the sequence below and    sum of terms.     1 + 1 + 2 + 3 + 5 + 8 + ...     2 3 5 7 11 13    * above Fibonacci sequence and below sequence of Cousins.

I have this exercise to do, but I can not. When I play the two together, it changes everything. But if I do separate, I can make the sequence perfectly.

How to solve?

My code so far: link

#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;
}
    
asked by anonymous 14.10.2014 / 03:30

1 answer

2

Instead of calculating and printing; calculates and puts into arrays. Then print the arrays.

int arrf[10]; // array para fibonacci
int arrp[10]; // array para primos

// calcula e guarda numeros
for (int k = 0; k < 10; k++) {
    arrf[k] = calculaf(k); // falta a definicao
    arrp[k] = calculap(k); // das funcoes calcula*
}

// imprime linha com numeros fibanacci
for (int k = 0; k < 10; k++) printf("%4d ", arrf[k]);
puts(""); // fim de linha

// imprime linha com numeros primos
for (int k = 0; k < 10; k++) printf("%4d ", arrp[k]);
puts(""); // fim de linha
    
14.10.2014 / 09:03