Computing a formula using do/while statements [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
who knows how to calculate the sum using the do/while operator using the formula below?
I would be grateful for any help.

Your formula can be translated like this:
double i = 1;
double sum = 0;
do{
sum += (1/i + 18*i);
i--;
} while (i < 16);
I'm not really sure that using a do while is the best option, it would probably be better with a for loop like so:
double sum = 0;
for (double i = 1; i < 16; ++i){
sum += (1/i + 18*i);
}

Related

How to loop over defined name pattern [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have around 500 signals with the naming pattern
"Dem_AllEventsStatusByte._101"
"Dem_AllEventsStatusByte._102"
"Dem_AllEventsStatusByte._103"
...
"Dem_AllEventsStatusByte._490"
I want to loop over all of them.
I tried the following code but when i=10 then my signal name is like " Dem_AllEventsStatusByte._1010" which is false it should be 110 at the end.
for (i=1; i<=3;i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._10%d", i);
How to loop over 490 signals of same name pattern? please help! Thank you
You probably want something this:
for (i = 1; i <= 490 - 100; i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._%d", i + 100);
or maybe this:
for (i = 101; i <= 490; i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._%d", i);

Converting cpp_int to binary string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can i convert boost cpp_int (>1000 bits) to it's binary representation in string (e.g. "1011....11001") ?
I have tried convert it by std::bitset, but it does not work on higher numbers
Edit - solution:
This contains a solution for this question:
Instead of int -> cpp_int
std::string toBinary(boost::multiprecision::cpp_int n)
{
std::string r;
while(n != 0)
{
r = (n % 2 == 0 ? "0":"1") + r;
n /= 2;
}
return r;
}

Equation Given : x = (((x+8)/3)%5)*5; solve the above equation using assignment operators (eg. +=, -=, *=) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Equation Given :  
x = (((x+8)/3)%5)*5;
solve the above equation using assignment operators (eg. +=, -=, *=).
Can someone help with this c++ problem?
sorry if this a dumb question
Technically, you can convert a single readable formula
x = (((x + 8) / 3) % 5) * 5;
into four ones:
x += 8;
x /= 3;
x %= 5;
x *= 5;

Increment a alpha numerical string abcd1234 upto abcd2000 in c or c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Increment a alpha numerical string "abcd1234" upto "abcd2000"
output:
abcd1234
abcd1235
.
.
.
abcd2000
Simply:
for (int a = 1234; a <= 2000; ++a)
{
std::cout << "abcd" << a;
}
In C,
for (int i=1234; i<= 2000;i++)
printf("abcd%d\n",i);

How can I shift signal in time in C++? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a signal x(t). I must shift it a/2 and -a/2 and then take the sum of these two shifted signals. How can I write shift of x(t) in time in C++?
For time series data a shift in time is just an offset of n samples, so to sum data which is shifted by +/-a/2 samples:
for (i = a/2; i < N - a/2; ++i)
{
y[i] = x[i - a/2] + x[i + a/2];
}