14,837,158 members
1.00/5 (1 vote)
See more:
input:4 terms 9+99+999+9999
expected output = 11106

What I have tried:

i tried but i didnt get output.
Posted
Updated 7-Apr-21 20:37pm
Patrice T 7-Apr-21 12:42pm

Solution 1

This is not a complex task, not even slightly.
All you have been asked to do is sum a number of terms, and you know how to do that - just add them up!

1) Get the number of terms.
2) Preset the total to 0; and the initial term to 9
3) Loop from zero to N - 1
3.1) Add the term to the total.
3.2) Multiply the term by ten, and add 9.
4) Print the total.
Maciej Los 8-Apr-21 2:26am

You're amazing, Master!

Solution 2

private int Nsum(int cnt)
{

int rtnValue = 0;

for (int i = 0; i < cnt; i++)
{
}

return rtnValue;
}
Maciej Los 8-Apr-21 2:27am

Do you really want to work on chars?
Jung-hoon's 8-Apr-21 20:22pm

Is there a simpler way?
Maciej Los 9-Apr-21 0:16am

[EDIT]
For example:
```int inp = 4;
int term = 9;
int temp = term;
int total = term;
for(int i=0; i<inp; i++)
{
temp *= 10;
temp += term;
Console.WriteLine(\$"current={total}; next={temp}");
total += temp;
}```
Jung-hoon's 9-Apr-21 2:59am

First of all, I'm sorry I'm not good at English.

Solution 1 is the basic method.
Faced with the problem, I thought it would be fun to use char.

You thought there was a new method that wasn't basic.
i'm sorry ^^
Jung-hoon's 9-Apr-21 3:03am

Thank you for responding to my playful answer.

You are a good man ^^
Maciej Los 9-Apr-21 5:13am

Thank you :)
:thumbsup:
Best wishes to you!