Implement various string algorithms
1. Reverse string
#include <iostream>using namespace std;int main(){char str[] = "Hello World";for(int i = 0; str[i] != '\0'; i++){for (int j = i+1; str[j] != '\0'; j++){char temp = str[i];str[i] = str[j];str[j] = temp;}}cout << str << endl;}
2. Length of string
#include <iostream>using namespace std;int main(){char str[] = "Hello World";int len = 0;for(int i = 0; str[i] != '\0'; i++){len++;}cout << len << endl;}
3.
0 Comments
Post a Comment