-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcode_1.cpp
More file actions
32 lines (28 loc) · 688 Bytes
/
code_1.cpp
File metadata and controls
32 lines (28 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// code_1.cpp
// Algorithm
//
// Created by Mohd Shoaib Rayeen on 23/11/18.
// Copyright © 2018 Shoaib Rayeen. All rights reserved.
//
#include <iostream>
using namespace std;
int sumOfSubstrings(string num) {
long n = num.length();
int sumofdigit[n];
sumofdigit[0] = num[0] - '0';
int res = sumofdigit[0];
for (int i = 1; i < n; i++ ) {
int numi = num[i] - '0';
sumofdigit[i] = (i+1) * numi + 10 * sumofdigit[i-1];
res += sumofdigit[i];
}
return res;
}
int main() {
string str;
cout << "\nEnter Number\t:\t";
getline(cin , str);
cout << "\nTotal Sum\t\t:\t" << sumOfSubstrings(str) << endl;
return 0;
}