Change the following C++ code to C code #include <iostream> using std::cout; #in
ID: 3615062 • Letter: C
Question
Change the following C++ code to C code#include <iostream>
using std::cout;
#include <iomanip> using std::setw;
#include <cmath>
bool prime( int n );
int main() { int count = 0;
cout << "The prime numbers from 1 to 10000are: ";
for ( int j = 2; j <= 10000; ++j ) if ( prime( j ) ) { ++count; cout << setw( 5 ) << j;
if ( count % 10 == 0 ) cout << ' '; }
return 0; }
bool prime( int n ) { for ( int i = 2; i <= static_cast< int > (sqrt( n ) ); ++i ) if ( n % i == 0 ) return false;
return true; } Change the following C++ code to C code
#include <iostream>
using std::cout;
#include <iomanip> using std::setw;
#include <cmath>
bool prime( int n );
int main() { int count = 0;
cout << "The prime numbers from 1 to 10000are: ";
for ( int j = 2; j <= 10000; ++j ) if ( prime( j ) ) { ++count; cout << setw( 5 ) << j;
if ( count % 10 == 0 ) cout << ' '; }
return 0; }
bool prime( int n ) { for ( int i = 2; i <= static_cast< int > (sqrt( n ) ); ++i ) if ( n % i == 0 ) return false;
return true; }
Explanation / Answer
//This programme will print all the number between 1 to 10000that are prime. void main() { printf("The prime numbers from 1 to 10000are: "); for ( int j = 1; j <= 10000; j++ ) { int flag=0; for(int i=2;i<j;i++) { if(j%i==0) flag++; } if(flag==0) printf("%d",j); } return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.