Sum of 1st 10 Prime Number

WAP to print sum of 1st 10 prime numbers starting from 1.

8 comments:

  1. #include
    main()
    {
    int i,p=1,n,sum=0,count=1;
    for(n=1; ;n++)
    {
    for(i=2;i10)
    break;
    if(p==1)
    {
    //printf("%d\n",n);
    sum+=n;
    count++;
    }
    }
    printf("The sum of 1st %d prime number is:%d\n",count-1,sum);
    }

    ReplyDelete
  2. /* sum of first 10 prime number */
    /* Author name:Md-Naimul Hasan shohan */
    #include
    using namespace std;
    void prime_num(int n)
    {
    cout<<"The first 10 prime number are:"<>n;
    prime_num(n);
    return 0;
    }

    ReplyDelete
  3. /*Sum of 1st 10 prime numbers */
    /* Author Name : Md Sazzad Hossain */
    /* AUB spring 2017 Section B - Uttara*/
    #include
    #include
    using namespace std;

    class primes{
    public:
    int i,j;
    void primeNumber(){
    for (i=2; i<30; i++){
    bool prime=true;
    for (j=2; j*j<=i; j++){
    if (i % j == 0){
    prime=false;
    break;
    }
    }
    if(prime){
    cout << i << " \n";
    }
    }
    }

    };

    int main(){
    primes obj;
    obj.primeNumber();
    return 0;
    }

    ReplyDelete
  4. #include
    #include
    using namespace std;

    class primes{
    public:
    int i,j;
    void primeNumber(){
    for (i=2; i<30; i++){
    bool prime=true;
    for (j=2; j*j<=i; j++){
    if (i % j == 0){
    prime=false;
    break;
    }
    }
    if(prime){
    cout << i << " \n";
    }
    }
    }

    };

    int main(){
    primes obj;
    obj.primeNumber();
    return 0;
    }

    ReplyDelete
  5. /*Shahenur islam,Id:201630405
    #include

    using namespace std;

    int main()
    {
    int i,j,count=1,b=0;
    cout<<"First Ten Prime Numbers Are\n"<<"2";

    for(i=3;i>0;++i)
    {
    for(j=2;j<=i/2;++j)
    {
    if(i%j==0){
    b=1;
    break;
    }
    }

    if(b==0)
    {
    cout<<"\n"<<i;
    count++;
    }

    b=0;
    if(count==10)
    break;
    }

    return 0;
    }

    ReplyDelete
  6. /*ID- 201630369 /*

    #include
    main()
    {
    int i,p=1,n,sum=0,count=1;
    for(n=1; ;n++)
    {
    for(i=2;i10)
    break;
    if(p==1)
    {
    //printf("%d\n",n);
    sum+=n;
    count++;
    }
    }
    printf("The sum of 1st %d prime number is:%d\n",count-1,sum);
    }

    ReplyDelete
  7. Mohammad Rakibul Hasan
    ID NO: 201520613

    \\Find the PRIME number


    #include
    using namespace std;
    int main()
    {
    int number,count=0;
    cout<<"ENTER NUMBER TO CHECK IT IS PRIME OR NOT \n";
    cin>>number;
    for(int a=1;a<=number;a++)
    {
    if(number%a==0)
    {
    count++;
    }
    }
    if(count==2)
    {
    cout<<" PRIME NUMBER \n";
    }
    else
    {
    cout<<" NOT A PRIME NUMBER \n";
    }

    }

    ReplyDelete