Advertisement
michael_xgrind

Sequencia de fracao fibonacci e primo

Oct 13th, 2014
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. /*
  2. h. Solicite ao usuário a quantidade de termos que ele deseja e imprima a sequencia abaixo e a
  3.    soma dos termos.
  4.     1      +      1       +      2      +        3     +        5    +       8     +…
  5.     2             3              5               7             11           13
  6.    * em cima sequencia de Fibonacci e embaixo sequencia de Primos.
  7.  
  8. */
  9.  
  10. #include "stdio.h"
  11.  
  12. main(){
  13.     int qtd, n1=0, n2=1, f=0, p=2, cont=0, j;
  14.     int a = 0;
  15.  
  16.     printf("Entre com a quantidade de termos: ");
  17.     scanf("%d", &qtd);
  18.  
  19.     for(int i=0; i<=qtd; i++){
  20.         cont=0;
  21.  
  22.         for(j=1; j<=i; j++){
  23.             if (i%j==0){
  24.                 cont++;
  25.             }
  26.         }
  27.  
  28.  
  29.  
  30.         if(i!=0){
  31.             if(cont==2){
  32.                 //printf("%d ", i);
  33.                 printf("%d/%d + ", f, i);
  34.             }
  35.         }
  36.  
  37.  
  38.         /*if(i!=0){
  39.             printf("%d + ", f);
  40.         }*/
  41.  
  42.             n1 = n2;
  43.             n2 = f;
  44.             f = n1+n2;
  45.         }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement