Simple math in C++: Difference between revisions
No edit summary |
wikademia>Wikademia m moved Simple Math to Simple math in C++ |
||
| (4 intermediate revisions by 4 users not shown) | |||
| Line 67: | Line 67: | ||
float myValue=25, myResult; | float myValue=25, myResult; | ||
myResult = sqrt(myValue); // Squareroot the variable myValue, and store it into variable myResult | myResult = sqrt(myValue); // Squareroot the variable myValue, and store it into variable myResult | ||
myResult = pow( | myResult = pow(myResult,2.00); // Square the variable myResult, and then store it back into myResult | ||
</pre></code> | </pre></code> | ||
| 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== | ||