lundi 17 décembre 2018

prime number program doesnt print anything-my error? [on hold]

This is my code for printing prime numbers till 20

#include<stdio.h>
int main()
{
    int num=3,lim,a=2,b,k;
    k=num%a;
    lim=20;
    for(num=3;num<=lim;num++)
    {
        for(a=2;a<num;a++)
        {
            if(k!=0)
            {
                b=3;
                b=+1;
                if(b==num)
                {
                    printf("%d\n",num);
                    break;
                }
            }
            else{
                break;
            }
        }
    }
}

The first loop is when each number is checked whether it is divisible by a or not and if it is not then that number will get printed on the screen

Now I don't know what is wrong because nothing gets printed and the command box says press any key to continue

any help would be highly appreciated

Aucun commentaire:

Enregistrer un commentaire