229k views
0 votes
Write a function called printBackwards() that will work with a C string. The function will print any C string backwards. You don't need to put in the prototype, but you need to write a complete function.

User Dalex
by
5.8k points

1 Answer

3 votes

Answer:

void printBackwards(char s[])

{

int n=strlen(s)-1;//finding the last index of the string..

for(int i=n;i>=0;i--)//loop to print the string backwards..

{

printf("%c",s[i]);//printing the character of the string..

}

}

Output:-

abcdefg

gfedcba

Step-by-step explanation:

I have used strlen function that will be used after including the string.h header file.It returns the length of the string.After finding the last index I have iterated over the c string in reverse order and printing the character of the string one by one.

User Sujit Prasad
by
6.5k points