Simple math in C++: Difference between revisions
wikademia>Wikademia m moved Simple Math to Simple math in C++ |
|||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 80: | Line 80: | ||
=== End of lesson 3 === | === End of lesson 3 === | ||
You should now be able to get C++ to do some simple math for you. In reality, it never gets much more complex than this. Almost everything you will write will be based on just a few simple operators. Thanks for reading this far. Hopefully you have learned something. | You should now be able to get C++ to do some simple math for you. In reality, it never gets much more complex than this. Almost everything you will write will be based on just a few simple operators. Thanks for reading this far. Hopefully you have learned something. Still, for your enhancement, following is the program that finds prime numbers until specified number: | ||
---- | |||
<code><pre> | |||
#include<iostream> | |||
using namespace std; | |||
int main(){ | |||
int n; | |||
cin>>n; | |||
for(int i=2;i<n;++i){ | |||
int count=0; | |||
for(int j=1;j<=n;++j) | |||
if(!(i%j)) | |||
++count; | |||
if(count==2) | |||
cout<<i<<endl; | |||
} | |||
return 0; | |||
} | |||
</pre></code> | |||
---- | |||
==Where To Go Next== | ==Where To Go Next== | ||