Monday, August 20, 2018

INVENTOR C

  • Problem Description

    Write a program to do the following:
    (a) To output the question - Who is the inventor of C??
    (b) To accept an answer.
    (c) To print out Good and then stop, if the answer is correct.

    To output the message try again if the answer is wrong.

    (d)To display the correct answer when the answer is wrong


    Hint:

    1.Declare a string variable and assign the value as DennisRitche
    2.Use string compare function to compare the input string and string already assigned
    3. If the input answer is wrong then display the message "try again" and display the correct answer

    Refer sample input and Output in the Test cases region.
  • CODING ARENA::
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      char name[50];
      char str[50]="DennisRitchie";
      scanf("%s",name); 
      if(strcmp(name,str)==0)
        {
        printf("Good");
        }
      else
        {
        printf("try again\nDennisRitchie");
      }
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    DennisRitchie
    
    
    Expected Output
    Good
  • Test Case 2

    Input (stdin)
    Gosling
    
    
    Expected Output
    try again
    
    DennisRitchie

No comments:

Post a Comment