### Program 94: To find the first capital letter in a given string

Program 94: To find the first capital letter in a given string
```#include<stdio.h>
#include<string.h>
main()
{
int i;
char str[100],c;
printf("Enter a string\n");
gets(str);

for(i=0;i<strlen(str);i++)
{
if(str[i]>='A'&&str[i]<='Z')
{
c=str[i];
break;
}
else
{
continue;
}
}
printf("First capital letter of string %s is %c\n",str,c);

}```
Explanation:

1. This program starts with initializing :
• str→ To store input from user
• i →Used as helping variable
• c→ To store output first capital letter
2. ```printf("Enter a string\n");
gets(str);```
To store string from user.For example str=hEllo
3.  Main logic of program
```for(i=0;i<strlen(str);i++)
{
if(str[i]>='A'&&str[i]<='Z')
{
c=str[i];
break;
}
else
{
continue;
}
}```
• Iteration 1: i=0 and 0<5 which is true so loop is executed
• str[0]=h which doesn't lie in between capital A to Z so the if part won't execute
• else part will be executed and the loop will continue to next iteration
• i is incremented by 1 ,i=1
• Iteration 2: i=1 and 1<5 which is true so loop is executed
• str[1]=E which lie in between capital A to Z so the if part is executed
• this letter E is stored in c,so c='E'
4. `printf("First capital letter of string %s is %c\n",str,c);`
Finally First capital letter is printed which is E

Output:

#### 1 comment:

1. factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

vegamovies Earlier people were not so much means to watch movies and to watch movies, we had to go to the movies hall where we were not allowed to go without tickets, but now people can watch movies online since the internet became cheaper.

 Donate Buy me a coffee \$2.00 USD Buy me a burger \$5.00 USD Buy me a pizza \$10.00 USD
 Compiler Used by me C-Free 5.0(Recommended) Other Compilers Code Blocks(Recommended) Online Compilers Ideone(Remember to give input before executing online where ever necessary)