Problem statement:- Program to Find the First small Letter in a given String
Data requirement:-
Input Data:- str
Output Data:- ch
Additional Data:-i, len in C++
Program in C
Here is the source code of the C Program to Find the First small Letter in a given String.
Output Data:- ch
Additional Data:-i, len in C++
Here is the source code of the C Program to Find the First small Letter in a given String.
Code:
#include<stdio.h>
#include<string.h>
int main()
{
char str[30];
printf("Enter your String:");
scanf("%[^\n]",str);
int i;
char ch;
for(i=0;i<strlen(str);i++)
{
if(str[i]>='a' && str[i]<='z')
{
ch=str[i];
break;
}
else
continue;
}
printf("First small letter in a given String is: %c",ch);
}
Input/Output:
Enter your String:CSinfo
First small letter in a given String is: i
Program in C++
Here is the source code of the C++ Program to Find the First small Letter in a given String.
First small letter in a given String is: i
Program in C++
Here is the source code of the C++ Program to Find the First small Letter in a given String.
Code:
#include<iostream>
using namespace std;
int main()
{
string str;
cout<<"Enter your String:";
getline(cin,str);
int len=0,i;
while(str[len]!='\0')
{
len++;
}
char ch;
for(i=0;i<len;i++)
{
if(str[i]>='a' && str[i]<='z')
{
ch=str[i];
break;
}
else
continue;
}
cout<<"First small letter in a given String is: "<<ch;
}
Input/Output:
using namespace std;
int main()
{
string str;
cout<<"Enter your String:";
getline(cin,str);
int len=0,i;
while(str[len]!='\0')
{
len++;
}
char ch;
for(i=0;i<len;i++)
{
if(str[i]>='a' && str[i]<='z')
{
ch=str[i];
break;
}
else
continue;
}
cout<<"First small letter in a given String is: "<<ch;
}
Input/Output:
Enter your String:CSINFO Dotcom
First small letter in a given String is: o
Program in Java
Here is the source code of the Java Program to Find the First small Letter in a given String.
First small letter in a given String is: o
Program in Java
Here is the source code of the Java Program to Find the First small Letter in a given String.
Code:
import java.util.Scanner;
public class p26 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str1;
System.out.println("Enter your String:");
str1=cs.nextLine();
char[] str=str1.toCharArray();
int i;
char ch = ' ';
for(i=0;i<str.length;i++)
{
if(str[i]>='a' && str[i]<='z')
{
ch=str[i];
break;
}
else
continue;
}
System.out.println("First small letter in a given String is:"+ch);
cs.close();
}
}
public class p26 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str1;
System.out.println("Enter your String:");
str1=cs.nextLine();
char[] str=str1.toCharArray();
int i;
char ch = ' ';
for(i=0;i<str.length;i++)
{
if(str[i]>='a' && str[i]<='z')
{
ch=str[i];
break;
}
else
continue;
}
System.out.println("First small letter in a given String is:"+ch);
cs.close();
}
}
Input/Output:
Enter your String:
JAVA pROGRAM
First small letter in a given String is:p
Program in Python
Here is the source code of the Python Program to Find the First small Letter in a given String.
JAVA pROGRAM
First small letter in a given String is:p
Here is the source code of the Python Program to Find the First small Letter in a given String.
Code:
str=input("Enter the String:")
ch=' '
for i in range(len(str)):
if str[i] >= 'a' and str[i] <= 'z':
ch = str[i]
break
else:
continue
print("First small letter in a given String is: ", ch)
ch=' '
for i in range(len(str)):
if str[i] >= 'a' and str[i] <= 'z':
ch = str[i]
break
else:
continue
print("First small letter in a given String is: ", ch)
Input/Output:
Enter the String:PYTHON pRogram
First small letter in a given String is: p
First small letter in a given String is: p
0 Comments
Please do not Enter any spam link in the comment box