Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write down a C program that should take a string as an input from the user. The

ID: 3803391 • Letter: W

Question

Write down a C program that should take a string as an input from the user. The program should ask the user for an option. Option should be a character variable, which can take values: 'u', 'U', 'I', 'L', and any other character. On the basis of the user input options the program should do the following: 1) If the option is 'u' or 'U' the input string should be converted to the uppercase string Example if the input string was "hello" the string should be changed to "HELLO". 2) If the option is 'I' or 'L', the input string should be converted to the lower case string. Example if the input string is "HELLO" the output string should be "hello". 3) For any other input option, the program should output: "Sorry incorrect option!"

Explanation / Answer

#include <stdio.h>
#include <string.h>
int main()
{
   char ch[100],op;
   int i,j,k;
   printf("Enter a string:");
   scanf("%s%*c",ch);
   printf("Choose an action: ");
   printf("1) Enter u or U for uppercase conversion. ");
   printf("2) Enter l or L for lowercase conversion. ");
   printf("Enter one of the options:");
   scanf("%c",&op);
   if(op=='u' || op=='U')
   {
       for(i=0;i<strlen(ch);i++)
       {
           if(ch[i]>='a' && ch[i]<='z')
           {
               ch[i] = ch[i]-'a'+'A';
           }
       }
       printf("%s ",ch);
   }
   else if(op=='l' || op=='L')
   {
       for(i=0;i<strlen(ch);i++)
       {
           if(ch[i]>='A' && ch[i]<='Z')
           {
               ch[i] = ch[i]-'A'+'a';
           }
       }
       printf("%s ",ch);
   }
   else
   {
       printf("Wrong option ");
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote