[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

can someone help me with this code it must be in c++ it's

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 18
Thread images: 1

File: Screenshot_1.png (5KB, 377x97px) Image search: [Google]
Screenshot_1.png
5KB, 377x97px
can someone help me with this code it must be in c++
it's say" write a code that do this:"

pic related
>>
>>57854788
explain that means ty
>>57854788
>>
>>57854788
You want the sum of every term from 1/1 to 1/1000^2.
Think about it, what does iterate through a finite numbers of elements.
>>
>>57854788
No. I'll give you the answer in python instead

print(sum(1 / i ** 2 for i in range(1, 10001)))
>>
>>57854788
>preface: I never wrote a C++ program in my life

>this is my attempt in 2 minutes, with 10 seconds of Googling

#include<cmath>       
#include<iostream>

int main ()
{
int sum = 0;
for (int i=0; i<10000; i++){
sum += 1 / pow(i,2);
}

cout << sum << endl;
}


It probably has a mistake but you can figure out a fix?
>>
>>57854788
You only need one loop of your choice.
>>
>>57854788
    double sum = 0;
for(int i=1;i<10000;i++){
sum+=1/(i*i);
}
cout << "Wilno nashe: "<< sum << endl;
>>
#include <cmath>
#include <iostream>

using namespace std;

int main(void)
{
cout << pow(4.0*atan(1.0), 2)/6.0 << endl;
return 0;
}

Near enough.
>>
>>57855152
Fuck you
>>
>>57854788
dumb polak
>>
>>57854788
#include <boost/math/special_functions/zeta.hpp>
#include <iostream>

int main() {
std::cout << boost::math::zeta<double>(2) << std::endl;
}


Your welcome ;^)
>>
>>57855123
Start with i=1 because you are dividing by it so you will hit a division by zero,
end with i<=1000 because it has to take into account the last element, if not it will go to 999 only.
>>
>>57855170
>Integer division
Pretty sure OP's still the one getting fucked
>>
>>57855123
It uses an int for the sum so all of the terms except for 1/1 will round to 0. It also divides by 0 on the first iteration
>>
Challenge: Make OP's code in the least efficient manner.
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;

for(int i = 0; i < 10000, i++)
{
for(int j = 0; j < i; j++)
{
sum1++;
}
for(int k = 0; k < sum1; k++
{
sum2 += sum1;
}
sum3 += 1 / sum2;
}
cout << sum3;
>>
Why people sum rational numbers to integers?
Fucking neo /g.
>>
>>57855195
you're advanced nig/g/a
>>
>>57855262
Challenge accepted.

This code is actually valid, it will just take forever to run:

int main()
{
auto inc = [](auto n) {
return -~n;
};

auto mul = [=](auto a, auto b) {
auto x = 0;
while (a != 0) {
for (int i=0; i<b; i = inc(i)) {
x = inc(x);
}
a += a - inc(a);
}
return x;
};

double result;

for (int i=1; i<10000; i=inc(i)) {
result += 1./(mul(i, i));
}

cout << result << endl;

return 0;
}
Thread posts: 18
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.