+ 1
I'm giving a code.. Can anyone explain this to me? Mostly 5, 11 & 12 line..
#include<stdio.h> int main() { char c[1200]; int sum[26]={}; int i; while(scanf("%s", c)!=EOF) { for(i=0; c[i] ; i++) { if('a'<=c[i]&&c[i]<='z')sum[c[i]-'a']++; if('A'<=c[i]&&c[i]<='Z')sum[c[i]-'A']++; } } for(i=0; i<26; i++) { printf("%c : %d\n",'a'+i,sum[i]); } return 0; }
2 Answers
+ 2
Line 5 initializes the whole sum[] array to zero values.
The 'for' loop in line 10 repeats until it finds a null character (0) in the string c. Null is the standard way that a string is terminated in the C language.
(Line 11 is the opening brace of the basic block to the 'for' statement).
Lines 12 and 13 determine the frequency of each alphabetic letter, case insensitive, that is found in the string c. In other words, it counts how many times each letter occurs. The sum[] array stores the counts -- sum[0] for letter A, sum[1] for B, sum[2] for C, sum[3] for D,... sum[25] for Z.
By the way, the code could be adjusted to do this more efficiently.
0
Can't help you this way, raw text code doesn't indicate line numbers. So please save that code in SoloLearn and share its link instead.
If you didn't know how, you can follow the below guide đ
https://www.sololearn.com/post/75089/?ref=app