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 >>
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.
উত্তরমুছুন#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();
}
// 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]);
}
}
উত্তরমুছুনBest way to find prime numbers in C | Sieve Of Erasthothanese method to generate prime numbers |
#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();
}
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;
}
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;
}
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;
}
r
উত্তরমুছুন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.
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
https://drive.google.com/open?id=0BzTqZMBWR6eONFVDNHFwcWgxWDg
উত্তরমুছুনhttps://drive.google.com/open?id=0BzTqZMBWR6eOQ1o5cEhmTkVCc00
উত্তরমুছুনhttps://drive.google.com/open?id=0BzTqZMBWR6eOdDNxcjg1V0RJalk
উত্তরমুছুন8. https://drive.google.com/open?id=0B8369pAqjVVpSDJfT08zY3E3OWc
উত্তরমুছুন1. wp. https://drive.google.com/open?id=0B8369pAqjVVpXzRBaEo2Zy1wN28
উত্তরমুছুনhttps://drive.google.com/open?id=0Byxq3aat_mNSUjdZemhBd2kwQnM
উত্তরমুছুনID 201610456
উত্তরমুছুনMD USUF MIA
https://drive.google.com/open?id=0B_PIGnOMR0K2MjRYYW8wdWF4R2c
ID:201520552
উত্তরমুছুনhttps://drive.google.com/open?id=0B5pG0kIjzgEKdXpreXZ5SjRDaEk
ID:201520552
উত্তরমুছুনhttps://drive.google.com/open?id=0B5pG0kIjzgEKdndaRlVYMkhyOUk
ID:201520552
উত্তরমুছুনhttps://drive.google.com/open?id=0B5pG0kIjzgEKdFJxMjJ5dmRHLUE
2.https://drive.google.com/open?id=0B7UQyRdu6h2wNkdVSS1keTUwVjQ
উত্তরমুছুনhttps://www.dropbox.com/s/u1uj39eh5flrx9h/Primes08.cpp?dl=0
উত্তরমুছুনID:-201610058
উত্তরমুছুন2.https://drive.google.com/open?id=0B7UQyRdu6h2wSXJxUG5VTkkwSU0