ASCII Sum

Description:

Find the sum of all ascii values of characters of a given string Test Case 1 Input (stdin) abcde Expected Output 495 Test Case 2 Input (stdin) srm Expected Output 338

Program :

#include<iostream>

using namespace std;

int main ()

{

    char str[50];

    int i, sum = 0;

   // cout << "Enter a string : ";

    cin>>str;

    for (i = 0; str[i] != '\0'; i++)

        sum = sum + str[i];

    cout << " " << sum;

    return 0;

}