SlideShare a Scribd company logo
1 of 2
Download to read offline
Program for prime numbers using Sieveof Eratosthenese Algorithm:
#include
#include
int main()
{
int p, i, primes[150], primeIndex = 2;
bool isPrime;
primes[0] = 2;
primes[1] = 3;
for(p = 5; p <= 150; p += 2) {
isPrime = true;
for(i = 1; isPrime && p / primes[i] >= primes[i]; i++)
if(p % primes[i] == 0)
isPrime = false;
if(isPrime == true) {
primes[primeIndex] = p;
primeIndex++;
}
}
for( i = 0; i < primeIndex; i++)
printf("%i ", primes[i]);
printf(" ");
return 0;
}
Solution
Program for prime numbers using Sieveof Eratosthenese Algorithm:
#include
#include
int main()
{
int p, i, primes[150], primeIndex = 2;
bool isPrime;
primes[0] = 2;
primes[1] = 3;
for(p = 5; p <= 150; p += 2) {
isPrime = true;
for(i = 1; isPrime && p / primes[i] >= primes[i]; i++)
if(p % primes[i] == 0)
isPrime = false;
if(isPrime == true) {
primes[primeIndex] = p;
primeIndex++;
}
}
for( i = 0; i < primeIndex; i++)
printf("%i ", primes[i]);
printf(" ");
return 0;
}

More Related Content

Similar to Program for prime numbers using Sieveof Eratosthenese Algorithm#i.pdf

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf
anithareadymade
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Jeff Tu Pechito
 
#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf
arjunchetri1
 
Check whether an Array is sorted or not
Check whether an Array is sorted or notCheck whether an Array is sorted or not
Check whether an Array is sorted or not
Ravi Ranjan
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 

Similar to Program for prime numbers using Sieveof Eratosthenese Algorithm#i.pdf (20)

Program presentation
Program presentationProgram presentation
Program presentation
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
insertion sort.pptx
insertion sort.pptxinsertion sort.pptx
insertion sort.pptx
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C
CC
C
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf
 
InsertionSort.pdf
InsertionSort.pdfInsertionSort.pdf
InsertionSort.pdf
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf
 
Check whether an Array is sorted or not
Check whether an Array is sorted or notCheck whether an Array is sorted or not
Check whether an Array is sorted or not
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdf
 
Lab Question
Lab QuestionLab Question
Lab Question
 
Vcs17
Vcs17Vcs17
Vcs17
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 

More from annamalaiagencies

massMass is the property which reflects the quan.pdf
                     massMass is the property which reflects the quan.pdf                     massMass is the property which reflects the quan.pdf
massMass is the property which reflects the quan.pdf
annamalaiagencies
 
The lyric solvers in MATLAB® solve these styles of first-order ODEs.pdf
The lyric solvers in MATLAB® solve these styles of first-order ODEs.pdfThe lyric solvers in MATLAB® solve these styles of first-order ODEs.pdf
The lyric solvers in MATLAB® solve these styles of first-order ODEs.pdf
annamalaiagencies
 
The most important criteria when a company is considering a supplier.pdf
The most important criteria when a company is considering a supplier.pdfThe most important criteria when a company is considering a supplier.pdf
The most important criteria when a company is considering a supplier.pdf
annamalaiagencies
 
The three safety measures that are critical to WLANS are as below..pdf
The three safety measures that are critical to WLANS are as below..pdfThe three safety measures that are critical to WLANS are as below..pdf
The three safety measures that are critical to WLANS are as below..pdf
annamalaiagencies
 
Live LoadsLive Load vs Dead LoadLive loads are consists of occup.pdf
Live LoadsLive Load vs Dead LoadLive loads are consists of occup.pdfLive LoadsLive Load vs Dead LoadLive loads are consists of occup.pdf
Live LoadsLive Load vs Dead LoadLive loads are consists of occup.pdf
annamalaiagencies
 
In our fingers, tendons are present. Tendons are bone-muscle attachm.pdf
In our fingers, tendons are present. Tendons are bone-muscle attachm.pdfIn our fingers, tendons are present. Tendons are bone-muscle attachm.pdf
In our fingers, tendons are present. Tendons are bone-muscle attachm.pdf
annamalaiagencies
 
i) Experiment is carried out to test whether B. cereus or soil bacte.pdf
i) Experiment is carried out to test whether B. cereus or soil bacte.pdfi) Experiment is carried out to test whether B. cereus or soil bacte.pdf
i) Experiment is carried out to test whether B. cereus or soil bacte.pdf
annamalaiagencies
 
Big Data in Healthcare Made Simple Where It Stands Today and Where .pdf
Big Data in Healthcare Made Simple Where It Stands Today and Where .pdfBig Data in Healthcare Made Simple Where It Stands Today and Where .pdf
Big Data in Healthcare Made Simple Where It Stands Today and Where .pdf
annamalaiagencies
 

More from annamalaiagencies (20)

volume of NaOh = Volume of HCl ( if both concent.pdf
                     volume of NaOh = Volume of HCl  ( if both concent.pdf                     volume of NaOh = Volume of HCl  ( if both concent.pdf
volume of NaOh = Volume of HCl ( if both concent.pdf
 
there is no picture figure of the compound provi.pdf
                     there is no picture figure of the compound provi.pdf                     there is no picture figure of the compound provi.pdf
there is no picture figure of the compound provi.pdf
 
nvm i got it. Nickel nitrate will split when goin.pdf
                     nvm i got it. Nickel nitrate will split when goin.pdf                     nvm i got it. Nickel nitrate will split when goin.pdf
nvm i got it. Nickel nitrate will split when goin.pdf
 
Which of the following are true when comparing TCPIP to the OSI Ref.pdf
Which of the following are true when comparing TCPIP to the OSI Ref.pdfWhich of the following are true when comparing TCPIP to the OSI Ref.pdf
Which of the following are true when comparing TCPIP to the OSI Ref.pdf
 
z = (x - mean)SDz = (50 - 42)10 = 0.8Solutionz = (.pdf
z = (x - mean)SDz = (50 - 42)10 = 0.8Solutionz = (.pdfz = (x - mean)SDz = (50 - 42)10 = 0.8Solutionz = (.pdf
z = (x - mean)SDz = (50 - 42)10 = 0.8Solutionz = (.pdf
 
massMass is the property which reflects the quan.pdf
                     massMass is the property which reflects the quan.pdf                     massMass is the property which reflects the quan.pdf
massMass is the property which reflects the quan.pdf
 
The lyric solvers in MATLAB® solve these styles of first-order ODEs.pdf
The lyric solvers in MATLAB® solve these styles of first-order ODEs.pdfThe lyric solvers in MATLAB® solve these styles of first-order ODEs.pdf
The lyric solvers in MATLAB® solve these styles of first-order ODEs.pdf
 
The most important criteria when a company is considering a supplier.pdf
The most important criteria when a company is considering a supplier.pdfThe most important criteria when a company is considering a supplier.pdf
The most important criteria when a company is considering a supplier.pdf
 
The three safety measures that are critical to WLANS are as below..pdf
The three safety measures that are critical to WLANS are as below..pdfThe three safety measures that are critical to WLANS are as below..pdf
The three safety measures that are critical to WLANS are as below..pdf
 
The data structures that are associated with system call areThe op.pdf
The data structures that are associated with system call areThe op.pdfThe data structures that are associated with system call areThe op.pdf
The data structures that are associated with system call areThe op.pdf
 
it is non linear order is 2 please repost the que.pdf
                     it is non linear order is 2 please repost the que.pdf                     it is non linear order is 2 please repost the que.pdf
it is non linear order is 2 please repost the que.pdf
 
Question seems incomplete. Please provide the table.Thanks!!So.pdf
Question seems incomplete. Please provide the table.Thanks!!So.pdfQuestion seems incomplete. Please provide the table.Thanks!!So.pdf
Question seems incomplete. Please provide the table.Thanks!!So.pdf
 
Note according to our guidelines we have to answer for one question.pdf
Note according to our guidelines we have to answer for one question.pdfNote according to our guidelines we have to answer for one question.pdf
Note according to our guidelines we have to answer for one question.pdf
 
Live LoadsLive Load vs Dead LoadLive loads are consists of occup.pdf
Live LoadsLive Load vs Dead LoadLive loads are consists of occup.pdfLive LoadsLive Load vs Dead LoadLive loads are consists of occup.pdf
Live LoadsLive Load vs Dead LoadLive loads are consists of occup.pdf
 
elemination reaction .pdf
                     elemination reaction                             .pdf                     elemination reaction                             .pdf
elemination reaction .pdf
 
In our fingers, tendons are present. Tendons are bone-muscle attachm.pdf
In our fingers, tendons are present. Tendons are bone-muscle attachm.pdfIn our fingers, tendons are present. Tendons are bone-muscle attachm.pdf
In our fingers, tendons are present. Tendons are bone-muscle attachm.pdf
 
D. orientation note ml decides the orientation .pdf
                     D. orientation  note ml decides the orientation .pdf                     D. orientation  note ml decides the orientation .pdf
D. orientation note ml decides the orientation .pdf
 
i) Experiment is carried out to test whether B. cereus or soil bacte.pdf
i) Experiment is carried out to test whether B. cereus or soil bacte.pdfi) Experiment is carried out to test whether B. cereus or soil bacte.pdf
i) Experiment is carried out to test whether B. cereus or soil bacte.pdf
 
Big Data in Healthcare Made Simple Where It Stands Today and Where .pdf
Big Data in Healthcare Made Simple Where It Stands Today and Where .pdfBig Data in Healthcare Made Simple Where It Stands Today and Where .pdf
Big Data in Healthcare Made Simple Where It Stands Today and Where .pdf
 
B. molar mass .pdf
                     B. molar mass                                    .pdf                     B. molar mass                                    .pdf
B. molar mass .pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 

Program for prime numbers using Sieveof Eratosthenese Algorithm#i.pdf

  • 1. Program for prime numbers using Sieveof Eratosthenese Algorithm: #include #include int main() { int p, i, primes[150], primeIndex = 2; bool isPrime; primes[0] = 2; primes[1] = 3; for(p = 5; p <= 150; p += 2) { isPrime = true; for(i = 1; isPrime && p / primes[i] >= primes[i]; i++) if(p % primes[i] == 0) isPrime = false; if(isPrime == true) { primes[primeIndex] = p; primeIndex++; } } for( i = 0; i < primeIndex; i++) printf("%i ", primes[i]); printf(" "); return 0; } Solution Program for prime numbers using Sieveof Eratosthenese Algorithm: #include #include int main() { int p, i, primes[150], primeIndex = 2; bool isPrime; primes[0] = 2;
  • 2. primes[1] = 3; for(p = 5; p <= 150; p += 2) { isPrime = true; for(i = 1; isPrime && p / primes[i] >= primes[i]; i++) if(p % primes[i] == 0) isPrime = false; if(isPrime == true) { primes[primeIndex] = p; primeIndex++; } } for( i = 0; i < primeIndex; i++) printf("%i ", primes[i]); printf(" "); return 0; }