This is a C Program to find the sum of ASCII values of all characters in a given string.
This program takes a string as input and finds the sum of ASCII values of all characters in a given string.
1. Take a string as input and store it in the array.
2. Add all the elements of the array.
3. Print the output and exit.
Here is source code of the C Program to find the sum of ASCII values of all characters in a given string. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program To Find the Sum of ASCII values of All Characters in a
* given String
*/
#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);
}
1. Take a string as input and store it in the array string[].
2. Initialize the variable sum to zero. Using for loop increment the variable sum with the elements of the array.
3. Print the variable sum as output.
Enter the string : Welcome to Sanfoundry's C Programming Class, Welcome Again to C Class ! Sum of all characters : 6307
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Computer Science Internship
- Buy Computer Science Books
- Practice BCA MCQs
- Apply for C Internship
- Buy C Books