See what questions your friends are asking today.

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?

Answer:

//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;
}

Contributors

«
LanceRas
Trust: 68
  • Computer Programming Supervisor
»

Top Contributors This Week

  • Trust Points: 2702
  • Member Since: 3/09
  • Trust Points: 4824
  • Member Since: 1/12
  • Trust Points: 1577
  • Member Since: 11/09
  • Trust Points: 3818
  • Member Since: 5/09
  • Trust Points: 1047
  • Member Since: 11/08