Saturday 11 November 2017

C Program to Find the Sum of ASCII values of All Characters in a given String


Code:

#include  stdio.h>
#include  string.h>

void main()
{
    int sum = 0, i, len;
    char string1[100];

    printf("Enter the string : ");
    scanf("%[^\n]s", string1);
        len = strlen(string1);
    for (i = 0; i < len; i++)
    {
        sum = sum + string1[i];
    }
    printf("\nSum of all characters : %d ",sum);
}

Output:

Enter the string : Welcome to Sanfoundry's C Programming Class, Welcome Again to C Class !

Sum of all characters : 6307


More C Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...