Program to reverse an input string and print the ASCII sum of the characters comprising the string

#include <stdio.h>
 
 int main()
 {
    const int MaxLine=100;     // Sets the limit of characters in string
    char Line[MaxLine];
    int i,Sum=0,ch;
 
    /*Read in the string*/
    printf("nEnter a set of characters : n");
    for(i=0;((ch=getchar())!='n');++i)
        Line[i]=(char)ch;
    Line[i]='';
 
    /*Print the reverse of the line*/
    printf("nThe reverse of the line entered is...n");
    while(i>0)
        putchar(Line[--i]);
 
    /*Print the sum of the ASCII values*/
    for(i=0;Line[i]!='';++i)
        Sum+=Line[i];
    printf("nnThe sum of the ASCII values is : %dn",Sum);
    return 0;
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.