Write a C program to find whether the number is prime or composite

#include <stdio.h>
main()
{
int a,i,b;
printf("enter no:");
scanf("%d",&a);
for(i=1;i<=a;a++)
if(a%i==0)
printf("the no is composite\n");
else
printf("the no is prime\n");
return 0;
}

Comments

  1. this is not accurate program plz check and up load a accurate program ok

    ReplyDelete
  2. there must be a break statement while printing the statement ...so code will be like this
    #include
    main()
    {
    int a,i,b;
    printf("enter no:");
    scanf("%d",&a);
    for(i=2;i<=a;a++)
    {
    if(a%i==0)
    {
    printf("the no is composite\n");
    break;
    }
    else
    {
    printf("the no is prime\n");
    break;
    }
    }
    return 0;
    }

    ReplyDelete

Post a Comment