**Using C Language** Please ester the initial character R Please enter the initi
ID: 3661601 • Letter: #
Question
**Using C Language**
Please ester the initial character R Please enter the initial character: The character you entered is Toe character you entered is its ASCIi code is L 821 ..........its ASCII code is I B6 The 5 by 5 matrix is R s T U v X Y Z Z Z UN Y Z Z Z Z z z z z z Fig. 4-3. Screenshots when entering 'R' or 'V Question 5 (30 points) Requirement: Write a program to read-in a string (ess than 20 characters, capital letters or lower letters combined with other characters are acceptable). Prompts the read-in string, corresponding Ascll codes, and their summation. In the meantime, the program can automatically convert the capital letter to lower letter vice versa. Then prompts the converted string, corresponding ASCII codes, and their summation. Notes: 1. Fig. 5 displays the required screenshot. 2. No point will be granted if you can only output the specified screenshot shown in Please input a string: Do you like NOKU? Q5 1: Do you like NOKU? Q5 2: 68 111 32 121 111 117 32 108 105 107 101 32 78 67 75 85 63 Q5 3: Summation of the ASCII code of the input string is [1413] Q5 4: ld0 YOU LIKE ncku? J Q5 5: 100 79 32 89 79 85 32 76 73 75 69 32 110 99 107 117 63 Q5 6: Its summation is now [1317] Fig. 5. Question 5 screenshotExplanation / Answer
#include<stdio.h>
void main(){
char string[100];
int i=0;
int stringlength; /* length of original array */
int sum=0; /* sum of ascii codes of original array */
int sum1=0 /* sum of ascii codes of changed array */
printf("Enter any string: ");
scanf("%s",string);
printf("ASCII values of every character of a given string: ");
while(string[i])
printf("%d ",string[i++]);
printf(“ the sum of ascii values is”);
stringlength = strlen(string);
for (i = 0; i < stringlength; i++)
{
sum = sum + string[i];
}
printf(" Sum of ascii values of all characters : %d ",sum);
/* convert uppercase to lower case and vice versa */
while (string[i] != '')
{ if (string[i]>=65 && string[i]<=90) /* if character is in uppercase */
string[i] += 32; /* change it to lowercase */
else
if (string[i] >=97 && string[i] <= 122) /* if character is in lowercase *.
string[i] -=32; /* change to uppercase */
++i;
}
printf(" The changed string is ->%s",string);
printf("ASCII values of every character of a changed string: ");
while(string[i])
printf("%d ",string[i++]);
printf(“ the sum of ascii values of changed array is”);
stringlength = strlen(string);
for (i = 0; i < stringlength; i++)
{
sum1 = sum1 + string[i];
}
printf(" Sum of asci values of all characters : %d ",sum1);
return 0;
}
Output
Enter any string:
ANKiT
Ascii values of every character of given string:
65 78 75 105 84
Sum of ascii values of all characters:
407
The changed array is :
ankIt
Ascii values of every character of changed string:
97 110 107 73 116
Sum of ascii values of all characters:
503
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.