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

C. Write a C program that prompts users to input 2 words. The program should the

ID: 3916583 • Letter: C

Question

C. Write a C program that prompts users to input 2 words. The program should then check whether the words entered are the same or different and print the output. Sample outputs are as shown below:

D. Write a C program that asks the user to input a word and prints it in the reverse order. Maximum characters in the word entered by user should be 50. Your program should continue to ask the user for a word and print it in reverse order till the user enters “quit”. Sample output is as shown below:

Enter first word: computer Enter second word: programming Output: computer and programming are different words Press any key to continue .. . Enter first word: computer Enter second word computer Output: computer and computer are the same Words Press any key to continue . ..

Explanation / Answer

#include<stdio.h>
#include<string.h>
int main()
{
char ch;
do
{
char str1[50],str2[50];
int i,l1,l2,f=0;
printf("Enter first word: ");
scanf("%s",&str1);

printf("Enter first word: ");
scanf("%s",&str2);

l1=strlen(str1);
l2=strlen(str2);
if(l1==l2)
{
for(i=0;i<l1;i++)
if(str1[i]!=str2[i]) {f=1; break;}
  
}
if(f) printf(" Output: %s and %s are different.... ",str1,str2);
else printf(" Output: %s and %s are same.... ",str1,str2);
printf(" Press any key to continue.... ");
scanf("%c",&ch);
}while(ch);
  
}

#include<stdio.h>
#include<string.h>
int is_quit(char a[])
{
int i;
char str[4]={"quit"};
for(i=0;i<4;i++)
if(str[i]!=a[i]) return 0;
return 1;
}
  
int main()
{
int ch=0;
char str2[10];
do
{
char str1[50];
int i,l1=0;
printf("Enter a word: ");
scanf("%s",&str1);



l1=strlen(str1);
printf(" Reverse of word: ");
for(i=l1-1;i>=0;i++) printf("%c",str1[i]);
printf("Continue..(1/0)?");
scanf("%d",&ch);
//scanf("%s",&str2);
}while(ch);
//while(!is_quit(str2));
}

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