Write a C program to accept a string from user and display its ascii value and then display sum of all ascii value of strings?

LanceRas Computer Programming Supervisor
//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include<stdio.h> #include <string.h> int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }
2 people found this useful

How to print ASCII values using c?

include <stdio.h> void main() { int c; printf("Please enter a string, terminate with Ctrl+Z"); for ((c=getchar())!=EOF) printf ("%c %d\\n", c, c); }

Thanks for the feedback!