Link to home
Start Free TrialLog in
Avatar of FxSedge
FxSedge

asked on

Calculate a firsts numbers

I have a program but this don't work, this programe had to calculate a firsts numbers of a serie, thanks.

#include <stdio.h>
#include <string.h>
#include <math.h>
void main()
{
        char c[255];
      long int m=1,cont1,cont2,b=2;
        printf("\n Tria si vols imprimir una llista de nombre parells,\n o una llista de nombres primers: ");
      scanf("%s",&c);
      printf("\nIntrodueix el primer numero de la serie: ");
      scanf("%ld",&cont1);
      printf("\nIntrodueix el segon numero de la serie: ");
      scanf("%ld",&cont2);
      if (!strcmp (c,"primers")){
            while (cont1<cont2){
                  while ((b>(cont1/2)) && (m!=0)){
                  if((cont1%b)!=0) b=b+1;
                  if((cont1%b)==0) m=0;
                  }
                  if (m==0){
                         printf("\nEl nombre %ld és primer",cont1);
                         m=1;
                         }
                  ++cont1;
                  }
      }
      if (!strcmp (c,"parells")){
            if((cont1%2)!=0) ++cont1;
            while (cont1<cont2){
                  printf("%ld\n", cont1);
                  ++cont1;
                  ++cont1;
                  }
              if((cont2/2)==0) printf("%ld",cont2);
      }        
}
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial