(a) Write a program to reverse a string
(b) Write a program that inputs a string with multiple words and then capitalizes the first
letter of each word.
Answers
Answer:
a
int main() { char s[100];
printf("Enter a string to reverse\n"); gets(s);
strrev(s);
printf("Reverse of the string: %s\n", s);
return 0; }
b
string = input('Enter line:')
length = len(string)
string2 = ''
for i in range(0, length):
if i == 0:
string2 += string[0].upper()
continue
elif string[i] == ' ':
string2 += string[i]
string2 += string[i+1].upper()
continue
elif string[i] != ' ':
if string2[i].upper() is True: # I feel like there is something wrong with this line
continue
else:
string2 += string[i]
print(string2)
s = input("enter string: ")
# (a) Write a program to reverse a string
print(s[::-1])
# write a program that inputs a string with multiple words and then
# capitalizes the first letter of each word.
print(" ".join(word[0].upper() + word[1:] for word in s.split()))