Home TechnologyProgrammingC++ Subscribe to RSS

Write A C++ Program That Will Display The Sum Of Prime Numbers From 1 To N?

Answer Question

1 Answer - Sort by: Date | Rating

    #include<iostream.h>
    #include<conio.h>

    int GetPrime(int);

    void main(){
    int number=0;
    cout<<"Enter a number to check:";
    cin>>number;
    int sum=0;

    for(int i=1;i<=number;i++)
        sum=sum+GetPrime(i);

    cout<<"Sum of Prime numbers:" <<sum;
    getch();
    }

    int GetPrime(int number){

    bool prime=true;
    for(int i=2;i<number;i++){
        if(number%i==0){
            prime=false;
            break;
        }
    }
    if (prime)
        return number;
    else
        return 0;
    }
    0 0

    Alon_nad 

    answered 4 months ago

    Offffffffoooo!!!!!!!! Jaha jao alone alone
    Report
    Gulzar06

    Gulzar06

    commented 4 months ago

      More

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International