Write a program to read two alphabetical characters and print all the characters in-between them including the given ones. Consider the 26 alphabets in cyclic order.
Note: use lower case letters for input and output.
For example:
Test Input Result
1 k o k l m n o
2 y a y z a
#include <stdio.h>
int main() {
char ch1, ch2, ch;
scanf("%c %c", &ch1, &ch2);
ch = ch1;
while (ch != ch2) {
printf("%c ", ch);
ch++;
if (ch > 'z') {
ch = 'a';
}
}
printf("%c\n", ch);
return 0;
}
Comments
Leave a comment