Index-1              Index-2              Home Page

Prime Number Manipulation

1. Write a C program to calculate the SUM and COUNT of Primes from a given range of numbers. Formatting required for the Input and Output statements.

Sample Input:

Range Start From: 1
End of Range: 10

Sample Output:

The Sum of Primes is: 11
Total Primes: 5

2. Write a C Program to Print all the Prime Numbers between 1 and 100. 

Sample Output:

1,  2,  3,  5,  7,  11,  13,  . . . . etc


3. WAP Program to get a range from user and give a list of prime numbers up to that number. And check whether the sum of all printed prime numbers are equal to the given input or not?
Sample Input: 10
Sample Output:
Prime list: 1, 2, 3, 5, 7
The sum is: 18
The sum is not equal to 10



1.                                                                                                                                                                 

main()
{
int a, b, c, n=0, start, end, sum=0;
printf("Range Start From: ");
scanf("%d", &start);
printf("End of Range: ");
scanf("%d", &end);

for(a=start;a<=end;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
sum+=a;
n++;
}
}
printf("The Sum of Primes is: %d\nTotal primes: %d", sum, n);
getch();
return 0;
}

2.                                                                                                                                                                  

main()
{
int a, b, c;

for(a=1;a<=100;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
printf("%d\t", a);
}
}
getch();
}

3.                                                                                                                                                                 


main()
{
int a, b, c,n,sum=0;
printf("Enter Range\n");
scanf("%d",&n);
printf("Prime list : ");
for(a=1;a<=n;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
printf("%d\t", a);
sum+=a;
}
}
printf("The sum is: %d",sum);

if (sum==n)
{
 printf("The sum is equal to %d",n);
}
else
{
printf("The sum is not equal to %d",n);
}

getch();
}
<< Go to Index Page >>

52 comments:

  1. 1.
    #include

    main()
    {
    int a, b, c, n=0, start, end, sum=0;
    printf("Range Start From: ");
    scanf("%d", &start);
    printf("End of Range: ");
    scanf("%d", &end);

    for(a=start;a<=end;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    sum+=a;
    n++;
    }
    }
    printf("The Sum of Primes is: %d\nTotal primes: %d", sum, n);
    getch();
    return 0;
    }

    ReplyDelete
  2. 2.
    #include

    main()
    {
    int a, b, c;

    for(a=1;a<=100;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    printf("%d\t", a);
    }
    }
    getch();
    }

    ReplyDelete
  3. // Write a C Program to Print all the Prime Numbers between 1 and 100//
    #include
    int main()
    {
    int a[100],b,c=2;
    for(b=0;b<100;b++)
    a[b]=b+1;
    printf("Prime numbers between 1 to 100: \n");
    for(b=0;b<100;b++)
    {
    for(c=2;a[b]>c;c++)
    {
    if(a[b]%c==0)
    break;
    }
    if(a[b]==c||a[b]==1)
    printf("%d\t",a[b]);
    }
    }

    ReplyDelete
  4. #include
    main()
    {
    int a, b, c,n;
    printf("enter the number.\n");
    scanf("%d",&n);
    for(a=1;a<=n;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    printf("%d\t", a);
    }
    }
    getch();
    }

    ReplyDelete
  5. Name:mahmuda sultana
    ID:201330499

    1...
    #include
    using namespace std;
    class A
    {
    public:
    int a, b, c, n=0,sum=0;
    int get_inp(int start,int endd)
    {
    x=start;
    y=endd;
    }
    protected:
    int x;
    int y;
    };
    class B:public A
    {
    public:
    int prime()
    {
    for(a=x;a<=y;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    sum+=a;
    n++;
    }
    }
    cout<<"The Sum of Primes is:"<>start;
    cout<<"End of Range: ";
    cin>>endd;
    bb.get_inp(start,endd);
    bb.prime();
    return 0;
    }

    ReplyDelete
  6. Id:201330499

    2...
    #include
    using namespace std;
    class A
    {
    public:
    int a, b, c;
    int prime(int m, int n)
    {
    x=m;
    y=n;
    }
    protected:
    int x;
    int y;
    };
    class B:public A
    {
    public:
    int prime_print()
    {
    for(a=x;a<=y;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }
    }
    if(c==1)
    {
    cout<<a<<endl;
    }
    }
    }
    };
    int main()
    {
    B bb;
    int m=1;
    int n=100;
    bb.prime(m,n);
    bb.prime_print();
    return 0;
    }

    ReplyDelete
  7. Id:201330499

    3.....
    #include
    using namespace std;
    class A
    {
    public:
    int a, b, c,n,sum=0;
    int get_inp(int m ,int n)
    {
    x=m;
    y=n;
    }
    protected:
    int x;
    int y;
    };
    class B:public A
    {
    public:
    int prime()
    {
    cout<<"Prime list :"<>m;
    cout<<"Enter last value:";
    cin>>n;
    bb.get_inp(m,n);
    bb.prime();
    return 0;
    }



    ReplyDelete
  8. Summer 2017
    ID#201610042

    Answer to Question No 8:

    problem 1: https://drive.google.com/file/d/0B99eePh0LV8gVDV6R2FYZVNRZ00/view?usp=drivesdk

    the answers to the problem 2 and 3 are similar to this solution.

    ReplyDelete
  9. ID : 201620195
    1) https://drive.google.com/open?id=0B9K31ospCyFjQ2xhczhDaW9YNkU

    2) https://drive.google.com/open?id=0B9K31ospCyFjb1R1QjNtd0F1ZTA

    3) https://drive.google.com/open?id=0B9K31ospCyFjbWJtY0xibkFJTms

    ReplyDelete
  10. https://drive.google.com/open?id=0BzTqZMBWR6eONFVDNHFwcWgxWDg

    ReplyDelete
  11. https://drive.google.com/open?id=0BzTqZMBWR6eOQ1o5cEhmTkVCc00

    ReplyDelete
  12. https://drive.google.com/open?id=0BzTqZMBWR6eOdDNxcjg1V0RJalk

    ReplyDelete
  13. 8. https://drive.google.com/open?id=0B8369pAqjVVpSDJfT08zY3E3OWc

    ReplyDelete
  14. 1. wp. https://drive.google.com/open?id=0B8369pAqjVVpXzRBaEo2Zy1wN28

    ReplyDelete
  15. https://drive.google.com/open?id=0Byxq3aat_mNSUjdZemhBd2kwQnM

    ReplyDelete
  16. ID 201610456
    MD USUF MIA
    https://drive.google.com/open?id=0B_PIGnOMR0K2MjRYYW8wdWF4R2c

    ReplyDelete
  17. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKdXpreXZ5SjRDaEk

    ReplyDelete
  18. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKdndaRlVYMkhyOUk

    ReplyDelete
  19. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKdFJxMjJ5dmRHLUE

    ReplyDelete
  20. 2.https://drive.google.com/open?id=0B7UQyRdu6h2wNkdVSS1keTUwVjQ

    ReplyDelete
  21. https://www.dropbox.com/s/u1uj39eh5flrx9h/Primes08.cpp?dl=0

    ReplyDelete
  22. ID:-201610058

    2.https://drive.google.com/open?id=0B7UQyRdu6h2wSXJxUG5VTkkwSU0

    ReplyDelete
  23. Name:Sumsunnahar Nawa
    ID:201710090
    Batch:54
    https://drive.google.com/file/d/1ATVpO0LAb9J5Ku4HLGdMJDhZpBSUJzD-/view?usp=sharing

    ReplyDelete
  24. //Problem 1

    #include
    using namespace std;

    //Editor: Md Rakibul Hasan Prince
    // ID: 201720620
    int sum=0,counter=0;

    class prime
    {
    public:
    int a,b;
    bool arr[1000001];

    prime()
    {
    cout<<"Range start from: ";
    cin>>a;
    cout<<"End of range: ";
    cin>>b;
    }

    void xisprime()
    {
    int i,j,x;
    memset(arr,true,sizeof(arr));
    arr[1]=false;

    for(i=2;i<sqrt(b);i++){
    if(arr[i])
    {
    for(j=i+i;j<=b;j+=i)
    arr[j]=false;
    }
    }

    }
    int calc(){
    int i;
    for(i=a;i<=b;i++){
    if(arr[i]){
    sum+=i;
    counter++;
    }
    }

    }
    ~prime()
    {
    }
    };
    int main()
    {
    cout<<"Program to sum and count prime numbers between the given range\n";
    prime ob;
    ob.xisprime();
    ob.calc();
    cout<<"Sum of primes is: "<<sum<<"\n"<<"Total primes: "<<counter<<"\n";
    return 0;
    }

    ReplyDelete
  25. //Problem 2
    //Editor: Md Rakibul Hasan Prince
    // ID: 201720620

    #include
    using namespace std;
    class prime
    {
    public:
    bool arr[101];

    prime()
    {
    int i,j,x;
    memset(arr,true,sizeof(arr));
    arr[1]=false;

    for(i=2;i<sqrt(100);i++){
    if(arr[i])
    {
    for(j=i+i;j<=100;j+=i)
    arr[j]=false;
    }
    }
    }
    int calc(){
    int i;
    for(i=1;i<=100;i++){
    if(arr[i]){
    cout<<i;
    if(i!=97)
    cout<<",";
    }
    }
    cout<<"\n";
    }
    ~prime()
    {
    }
    };
    int main()
    {
    cout<<"Program print prime numbers among 100\n";
    prime ob;
    ob.calc();
    return 0;
    }

    ReplyDelete
  26. //Problem 3
    //Editor: Md Rakibul Hasan Prince
    // ID: 201720620

    #include
    using namespace std;
    class prime
    {
    public:
    bool arr[1000000];

    prime()
    {
    int i,j,x;
    memset(arr,true,sizeof(arr));
    arr[1]=false;

    for(i=2; i>n;
    prime ob;
    ob.lst(n);
    ob.calc(n);
    return 0;
    }

    ReplyDelete
  27. https://drive.google.com/open?id=1_BCvdGvgqX74KNsmK8U1zwcfKv4Dn7fA
    ID: 201710404

    ReplyDelete
  28. Name:Sumsunnahar nawa
    ID:201710090
    Batch:54(CSE)
    https://drive.google.com/open?id=1P9jJ2B0VXhEUWL8kcfGoEPFIbpyNcs2u

    ReplyDelete
  29. Name:Sumsunnahar nawa
    ID:201710090
    Batch:54
    https://drive.google.com/open?id=1Uj0FdwubOvRVUAJNJh9hDhTqsdhesPwy

    ReplyDelete
  30. ID #201611036
    1. Link--> https://drive.google.com/open?id=1LsrMwzyQ3zQwA_APT9YM7mOZI9vS6htB
    2. Link--> https://drive.google.com/open?id=1NVSn-sOrc0Xap2BrXBdP2KozaUfloh4Q

    ReplyDelete
  31. ID #201610288

    1.https://drive.google.com/open?id=1CU1nV49x7SyIxAAJEDJFrEllRX8fGw1Miinkm74djME

    2.https://drive.google.com/open?id=1RcZNIggPa_gKYCaH7V_Nx6HIn-5ISc9YUs_PXNGTEC0

    3.https://drive.google.com/open?id=1FX2kl5wN7wW0cPKk0pulOrY_JDa2uljZYE_HTu4ounQ

    ReplyDelete
  32. ID:201820244
    Batch:58th
    Section:B

    #include
    void main()
    {
    int i,j;
    for (i=0;i<=100;i++)
    {
    for(j=2;j<i;j++)
    {
    if(i%j==0)
    break;
    }
    if (i==j)
    printf("\n No this prime numer: %d",i);
    }
    }

    ReplyDelete
  33. #include
    void main()
    {
    int i,j;
    for (i=0;i<=100;i++)
    {
    for(j=2;j<i;j++)
    {
    if(i%j==0)
    break;
    }
    if (i==j)
    printf("\n No this prime numer: %d",i);
    }
    }

    ReplyDelete
  34. ID:201820244
    Batch:58th
    Section:B

    main()
    {
    int i, j, count1, n=0,start,end,sum=0;
    printf("please enter start range number: ");
    scanf("%d", &start);
    printf("End of range: ");
    scanf("%d", &end);

    for(i=start;i<=end;i++)
    {
    count1=1;
    for(j=2;j<=i/2;j++)
    {
    if(i%j==0)
    {
    count1=0;
    break;
    }
    }
    if(count1==1)
    {
    sum+=i;
    n++;
    }
    }

    printf("The Sum of Primes is: %d\nTotal primes: %d", sum, n);


    return 0;
    }

    ReplyDelete
  35. main()
    {
    int i, j, count1, n=0,start,end,sum=0;
    printf("please enter start range number: ");
    scanf("%d", &start);
    printf("End of range: ");
    scanf("%d", &end);

    for(i=start;i<=end;i++)
    {
    count1=1;
    for(j=2;j<=i/2;j++)
    {
    if(i%j==0)
    {
    count1=0;
    break;
    }
    }
    if(count1==1)
    {
    sum+=i;
    n++;
    }
    }

    printf("The Sum of Primes is: %d\nTotal primes: %d", sum, n);


    return 0;
    }

    ReplyDelete
  36. Name : Firoj Ahmed
    ID : 201820222
    Batch : 58th
    Section : B

    1.

    #include
    #include
    using namespace std;

    class number
    {
    int up, down, count;
    long long sum;

    bool isprime(int x)
    {
    if (x==2)
    return true;
    if (x!=2&&!(x%2))
    return false;

    int m = (int) sqrt ((double) x);

    for (int i=3; i<=m;i+=2)
    {
    if (!(x%i))
    {
    return false;
    }
    }

    return true;
    }

    public:

    number()
    {
    up=down=count=sum=0;
    }

    void get_range(void)
    {
    cout<<"Range strat from: ";
    cin>>down;
    cout<<"Range ends at: ";
    cin>>up;
    }
    void count_prime(void)
    {
    if (down==1)
    down=2;
    for (int i=down; i<=up; i++)
    {
    if (i!=2&&!(i%2))
    continue;

    if (isprime(i))
    {
    count++;
    sum+=i;
    }
    }
    }

    void print_result(void)
    {
    cout<<"The sum of primes= "<
    #include
    using namespace std;

    class myPrime
    {
    public:
    void prime(int pn)
    {
    int i,j,squ,f,sum=0;

    cout << "Prime list: ";
    for(i=2; i<=pn; i++)
    {
    f = 1;

    if(i==2)
    {
    sum += i;
    cout << i;
    continue;
    }
    else if(i%2==0)
    continue;

    squ = (int)sqrt((double)i);
    for(j=3; j<=squ; j+=2)
    {
    if(i%j==0)
    {
    f = 0;
    break;
    }
    }
    if(f)
    {
    cout << ", ";
    sum += i;
    cout << i;
    }
    }
    cout << endl;
    cout << "The sum is: " << sum << endl;

    if(pn==sum)
    cout << "The sum is equal to "<> pn;

    p.prime(pn);
    return 0;
    }

    ReplyDelete
  37. ID:201820244
    Batch:58th
    section:B
    I used constructor & destructor

    #include
    using namespace std;
    class primenumber
    {
    public:
    int num, i, x=0;
    bool isPrime = true;
    primenumber()
    {
    cout << "Enter a positive integer: ";
    cin>>num;
    }
    ~ primenumber()
    {

    }
    int checkp()
    {
    for(i = 2; i <= num / 2; ++i)
    {
    if(num % i == 0)
    {

    if (isPrime == false)
    x=0;
    else
    x=1;
    }
    }

    }
    };
    int main()
    {
    primenumber p;
    p.checkp();
    //cout<<p.x;
    if (p.x == 1)
    cout<<"This number is not prime";
    else
    cout<<"This number is prime";
    }

    ReplyDelete
  38. Id:201820244
    Batch:58th
    section:B
    Only Constructor
    Used this Program

    #include
    using namespace std;
    class primenumber
    {
    public:
    int num, i, x=0;
    bool isPrime = true;
    primenumber()
    {
    cout << "Enter a positive integer: ";
    cin>>num;

    }
    int checkp()
    {
    for(i = 2; i <= num / 2; ++i)
    {
    if(num % i == 0)
    {

    if (isPrime == false)
    x=0;
    else
    x=1;
    }
    }

    }
    };
    int main()
    {
    primenumber p;
    p.checkp();
    //cout<<p.x;
    if (p.x == 1)
    cout<<"This number is not prime";
    else
    cout<<"This number is prime";
    }

    ReplyDelete
  39. ID: 201820244
    Batch:58th
    section:B
    This program class name & function name different,So I try to use check method this program.

    #include
    using namespace std;
    class primenumber
    {
    public:
    int num, i, x=0;
    bool isPrime = true;
    check_prime ()
    {
    cout << "Enter a positive integer: ";
    cin>>num;

    }
    int checkp()
    {
    for(i = 2; i <= num / 2; ++i)
    {
    if(num % i == 0)
    {

    if (isPrime == false)
    x=0;
    else
    x=1;
    }
    }

    }
    };
    int main()
    {
    primenumber p;
    p.check_prime ();
    //cout<<p.x;
    if (p.x == 1)
    cout<<"This number is not prime";
    else
    cout<<"This number is prime";
    }


    ReplyDelete
  40. ID:201820244
    batch:58th
    section B

    #include
    #include
    using namespace std;

    class Prime
    {
    public:
    void prime(int ps,int pe)
    {
    int i,j,squ,f,sum=0,c=0;

    if(ps==1)
    ps++;

    for(i=ps; i<=pe; i++)
    {
    f = 1;
    squ = (int)sqrt((double)i);
    for(j=2; j<=squ; j++)
    {
    if(i%j==0)
    {
    f = 0;
    break;
    }
    }
    if(f)
    {
    sum += i;
    c++;
    }
    }

    cout << "The Sum of Primes is: " << sum << endl;
    cout << "Total Primes: " << c << endl;
    }
    };


    int main()
    {
    Prime obj;
    int ps,pe;
    cout << "Range Start From: ";
    cin >> ps;
    cout << "End of Range: ";
    cin >> pe;
    obj.prime(ps,pe);
    return 0;
    }

    ReplyDelete
  41. #include
    using namespace std;
    class manush
    {
    public:
    int age;
    manush()
    {
    cout<<"Enter your age: ";
    cin>>age;
    }

    Checkshow_status(void)
    {
    if (age<0)
    cout<<"You haven't born yet!"<<endl;
    else if (age<18)
    cout<<"You are a child"<<endl;
    else if (age<65)
    cout<<"You are an adult"<<endl;
    else
    cout<<"You are a senior citizen"<<endl;
    }
    };

    int main()
    {
    manush obj;
    obj.Checkshow_status();
    return 0;
    }
    Construcor program

    id:201820244

    ReplyDelete
  42. 1.
    #include
    using namespace std;
    class a
    {
    public:
    int f,s,e;
    a()
    {
    cout<<"Range start from : ";
    cin>>s;
    cout<<"End of range : ";
    cin>>e;
    }
    ~a()
    {
    }

    };
    class b:public a
    {
    private:
    int i,j;
    public:
    int sum=0,c=0;
    void process()
    {
    for(i=s;i<e;i++)
    {
    for(j=2;j<i;j++)
    {
    f=1;
    if(i%j==0)
    {
    f=0;
    break;
    }
    }
    if(f==1)
    {
    sum=sum+i;
    c++;
    }
    }
    if(s==1)
    {
    cout<<"The sum of prime is: "<<sum+3;
    cout<<"\n Total prime : "<<c+2;
    }
    else
    {
    cout<<"The sum of prime is: "<<sum;
    cout<<"\n Total prime : "
    <<c;
    }
    }
    };
    int main()

    {
    b obj1;
    obj1.process();
    }

    ReplyDelete
  43. 2.
    #include
    using namespace std;
    class a
    {
    public:
    int f;
    a()
    {
    cout<<"All the prime numbers are : ";

    }
    ~a()
    {
    }

    };
    class b:public a
    {
    private:
    int i,j;
    public:

    void process()
    {
    for(i=1;i<100;i++)
    {
    for(j=2;j<i;j++)
    {
    f=1;
    if(i%j==0)
    {
    f=0;
    break;
    }
    }
    if(f==1)
    {

    cout<<i<<", ";
    }
    }

    }
    };
    int main()

    {
    b obj1;
    obj1.process();
    }

    ReplyDelete
  44. 3.
    #include
    using namespace std;
    class a
    {
    public:
    int n,f;
    a()
    {
    cout<<"Enter range: ";
    cin>>n;
    cout<<"\nThe prime numbers are : ";

    }
    ~a()
    {
    }

    };
    class b:public a
    {
    private:
    int i, j;
    public:
    int s, sum=0;
    void process()
    {
    for(i=1;i<n;i++)
    {
    for(j=2;j<i;j++)
    {
    f=1;
    if(i%j==0)
    {
    f=0;
    break;
    }
    }
    if(f==1)
    {

    cout<<i<<", ";
    sum=sum+i;
    }
    }
    s=sum+3;
    cout<<"\nThe sum is : "<<s;
    if(s==n)
    cout<<"\nThe sum is equal to "<<n;
    else
    cout<<"\nThe sum is not equal to "<<n;

    }
    };
    int main()

    {
    b obj1;
    obj1.process();
    }

    ReplyDelete
  45. #ID 201630992
    Sijar khan
    section: A

    #include
    using namespace std;

    class A
    {
    public:
    int a,b,c,s,e,n=0,sum=0;

    A()
    {
    cout<<"Enter How Many Number: ";
    cin>>s;

    cout<<"Enter How Many Number: ";
    cin>>e;

    }
    ~A()
    {

    }

    };
    class B : public A
    {
    public:

    void display()
    {

    for(a=s;a<=e;a++)
    {
    c=1;
    for(b=2;b<=a/2;b++)
    {
    if(a%b==0)
    {
    c=0;
    break;
    }

    }

    if(c==1)
    {
    sum = sum + a;
    n++;
    cout<<a <<" " <<endl;
    }

    }

    cout<<"Total Prime: "<<n <<endl;
    cout<<"The sum of prime is: "<<sum;


    }


    };

    int main()
    {
    B obj;

    obj.display();
    }



    ReplyDelete
  46. rownak jahan rituJune 30, 2019 at 11:46 PM

    2.
    #include
    using namespace std;
    class A
    {
    public:
    int i,n;
    A()
    {
    cout<<"enter number=";
    cin>>n;
    }
    };
    class B:public A
    {
    public:
    int f,j,c=0;
    void res()
    {
    for(i=1;i<=n;i++)
    {
    for(j=2;j<i;j++)
    {

    if(i%j==0)
    {
    f=0;
    break;
    }
    else
    f=1;


    }
    if(f==1)
    {
    cout<<i<<" ";
    c++;
    }
    }


    };
    };
    int main()
    {
    B obj1;
    obj1.res();
    }



    ReplyDelete
  47. rownak jahan rituJune 30, 2019 at 11:47 PM

    2.
    #include
    using namespace std;
    class A
    {
    public:
    int i,n;
    A()
    {
    cout<<"enter number=";
    cin>>n;
    }
    };
    class B:public A
    {
    public:
    int f,j,c=0;
    void res()
    {
    for(i=1;i<=n;i++)
    {
    for(j=2;j<i;j++)
    {

    if(i%j==0)
    {
    f=0;
    break;
    }
    else
    f=1;


    }
    if(f==1)
    {
    cout<<i<<" ";
    c++;
    }
    }


    };
    };
    int main()
    {
    B obj1;
    obj1.res();
    }



    ReplyDelete
  48. rownak jahan rituJuly 1, 2019 at 2:25 AM

    1

    #include
    using namespace std;
    class A
    {
    public:
    int i,j,n,sum=0,s,e;
    A()
    {
    cout<<"start : ";
    cin>>s;
    cout<<"end : ";
    cin>>e;
    }
    };
    class B:public A
    {
    public:
    int f,c=0;
    void res()
    {
    for(i=s;i<=e;i++)
    {
    f=1;
    for(j=2;j<i;j++)
    {
    if(i%j==0)
    {
    f=0;
    break;
    }
    }
    if(f==1)
    {
    sum=sum+i;
    c++;
    }
    }
    cout<<sum<<endl;
    cout<<c;
    }

    };
    int main()
    {
    B obj1;
    obj1.res();
    }

    ReplyDelete
  49. rownak jahan rituJuly 1, 2019 at 2:36 AM


    2
    #include
    using namespace std;
    class A
    {
    public:
    int i,j,n,sum=0,s,e;
    A()
    {

    cout<<"Enter input : ";
    cin>>e;
    }
    };
    class B:public A
    {
    public:
    int f,c=0;
    void res()
    {
    for(i=1;i<=e;i++)
    {
    f=1;
    for(j=2;j<i;j++)
    {
    if(i%j==0)
    {
    f=0;
    break;
    }
    }
    if(f==1)
    {
    //sum=sum+i;
    cout<<i<<endl;

    }

    }
    }

    };
    int main()
    {
    B obj1;
    obj1.res();
    }

    ReplyDelete
  50. rownak jahan rituJuly 2, 2019 at 3:22 AM

    3.
    #include
    using namespace std;
    class A
    {
    public:
    int i,j,n,sum=0,s,e;
    A()
    {

    cout<<"Enter input : ";
    cin>>e;
    }
    };
    class B:public A
    {
    public:
    int f,c=0;
    void res()
    {
    for(i=1;i<=e;i++)
    {
    f=1;
    for(j=2;j<i;j++)
    {
    if(i%j==0)
    {
    f=0;
    break;
    }
    }
    if(f==1)
    {
    sum=sum+i;
    cout<<i<<endl;

    }

    }

    cout<<"sum is : "<<sum;
    if(sum==e)
    cout<<"\nThe sum is equal to "<<e;
    else
    cout<<"\nThe sum is not equal to "<<e;

    }

    };
    int main()
    {
    B obj1;
    obj1.res();
    }

    ReplyDelete