Print all prefixes?

#include<iostream>
using namespace std ;

void print_all_prefixes(char str[]){

for (int i = 0; str[i] != '\0'; ++i) {
for (int j = 0; j <= i ; ++j) {
cout << str[j] ;
}
cout << '\n' ;
}
}

int main(){
char str[] = "abcd" ;
print_all_prefixes(str) ;


return 0 ;
}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2