Assignments » String » Set1 »Solution 9

Write a program to convert a string in lowercase.

#include<iostream>
using namespace std;

int main( )
{
    char str[80];

    cout<<"Enter string: ";
    cin.getline(str, 80);
    
    for(int i=0;str[i]!='\0';i++)
    {
        str[i] = (str[i] >= 'A' && str[i] <= 'Z') ? (str[i] + 32) : str[i];
    }

    cout<<"Lowercase string: " << str << endl;
	
    return 0;
}

Enter string: Hello World
Lowercase string: hello world

 

 

«back