Can someone help me with my C program Homework, I'm have some problems
Question
Write a C program using switch case statement, which provides multiple functions such
as:
1. Find length of the string using predefined string function.
2. Change Upper case string to Lower case string using predefined string function.
3. Find largest value out of two numbers.
4. Find your given value is Odd or Even
My C program so far:
#include
main()
{
int choice,i,a,b,c;
char str1[20],str2[20];
printf("\n Enter the first Value:");
gets(str1);
printf("\n Enter the Second Value:");
gets(str2);
printf("\n 1------> Length of the String");
printf("\n 2------> Upper Case to Lower Case");
printf("\n 3------> largest value out of two Values");
printf("\n 4------> Odd or Even");
printf("\n What is your Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
i=strlen(a);
printf("the length of the string is =%d",i);
break;
}
case 2:
{
puts(strupr(str1));
printf("\n Upper Case to Lower Case=%d",i);
break;
}
case 3:
{
if(str1 > str2)
{
printf("%d is Largest\n", str1);
}
else if (str2 > str1)
{
printf("%d is Largest\n", str2);
}
else
{
printf("Both are Equal\n");
break;
}
case 4:
{
str2 = str1 % 2;
if (str2 == 0)
printf("%d is an even integer\n", str1);
else
printf("%d is an odd integer\n", str1);
break;
}
default:
printf("\n Your Choice is Wrong try one more time:");
break;
}
}
}
Answers
Answer:
Question
Write a C program using switch case statement, which provides multiple functions such
as:
1. Find length of the string using predefined string function.
2. Change Upper case string to Lower case string using predefined string function.
3. Find largest value out of two numbers.
4. Find your given value is Odd or Even
Answer:
There is your Answer, Please make me brainliest :
Explanation:
// Answer :
#include <stdio.h>
#include <string.h>
int main()
{
char string[100];
int length, answer, number1, number2;
printf("Enter a string:\n");
gets(string);
printf("Enter a first number:\n");
scanf("%d",&number1);
printf("Enter a second number:\n");
scanf("%d",&number2);
printf("Enter the your answer number:\n");
scanf("%d",&answer);
switch (answer)
{
case 1:
length = strlen(string);
printf("Length of the string = %d\n", length);
break;
case 2:
printf(strlwr(string));
break;
case 3:
if (number1 > number2 )
{
printf("%d is greater than %d.\n", number1, number2);
}
else
printf("%d is greater than %d.\n", number2, number1);
break;
case 4:
if (number1 % 2 == 0 )
{
printf("%d is even number.\n", number1);
}
else
printf("%d is odd number.\n", number1);
if (number2 % 2 == 0 )
{
printf("%d is even number.\n", number2);
}
else
printf("%d is odd number.\n", number2);
break;
default:
printf("*Your Choice is Wrong try one more time.*\n");
break;
}
return 0;
}
// Thank you