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 >>

24 মন্তব্যসমূহ

  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;
    }

    উত্তরমুছুন
  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();
    }

    উত্তরমুছুন
  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]);
    }
    }

    উত্তরমুছুন
  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();
    }

    উত্তরমুছুন
  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;
    }

    উত্তরমুছুন
  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;
    }

    উত্তরমুছুন
  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;
    }



    উত্তরমুছুন
  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.

    উত্তরমুছুন
  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

    উত্তরমুছুন
  10. https://drive.google.com/open?id=0BzTqZMBWR6eONFVDNHFwcWgxWDg

    উত্তরমুছুন
  11. https://drive.google.com/open?id=0BzTqZMBWR6eOQ1o5cEhmTkVCc00

    উত্তরমুছুন
  12. https://drive.google.com/open?id=0BzTqZMBWR6eOdDNxcjg1V0RJalk

    উত্তরমুছুন
  13. 8. https://drive.google.com/open?id=0B8369pAqjVVpSDJfT08zY3E3OWc

    উত্তরমুছুন
  14. 1. wp. https://drive.google.com/open?id=0B8369pAqjVVpXzRBaEo2Zy1wN28

    উত্তরমুছুন
  15. https://drive.google.com/open?id=0Byxq3aat_mNSUjdZemhBd2kwQnM

    উত্তরমুছুন
  16. ID 201610456
    MD USUF MIA
    https://drive.google.com/open?id=0B_PIGnOMR0K2MjRYYW8wdWF4R2c

    উত্তরমুছুন
  17. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKdXpreXZ5SjRDaEk

    উত্তরমুছুন
  18. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKdndaRlVYMkhyOUk

    উত্তরমুছুন
  19. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKdFJxMjJ5dmRHLUE

    উত্তরমুছুন
  20. 2.https://drive.google.com/open?id=0B7UQyRdu6h2wNkdVSS1keTUwVjQ

    উত্তরমুছুন
  21. ID:-201610058

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

    উত্তরমুছুন
নবীনতর পূর্বতন