Find the length of the following strings
char str1[] = "I love C+++ Programming! ";
char str2[] = "This is so cool!";
char str3[] = "Good job learner!";
The output should be like the following format:
The length of str1 is __
The length of str2 is __
The length of str3 is __
#include<iostream>
using namespace std;
int main(){
char str1[] = "I love C+++ Programming! ";
char str2[] = "This is so cool!";
char str3[] = "Good job learner!";
int counter = 0;
for(auto x: str1){
counter += 1;
}
int counter1 = 0;
for(auto x: str2){
counter1 += 1;
}
int counter2 = 0;
for(auto x: str3){
counter2 += 1;
}
cout<<"The length of str1 is "<<counter<<endl;
cout<<"The length of str2 is "<<counter1<<endl;
cout<<"The length of str3 is "<<counter2<<endl;
}
Comments
Leave a comment