Tuesday, May 14, 2019

Shape Up

  • Problem Description

    Write a program that determines the name of a shape from its number of sides. Read the number of sides from the user and then report the appropriate name as part of a meaningful message. 

    Your program should support shapes with anywhere from 7 up to (and including) 10 sides. 

    If a number of sides outside of this range is entered then your program should display an appropriate error message.

    1. If the input is 9 then display as Nanogon

    2. If the input is 10 display as Decagon

    3. If the input is any another number then display the message "Input should be from 7 to 10"

    Mandatory:

    Use Switch case
  • Test Case 1

    Input (stdin)
    7

    Expected Output
    Heptagon
  • Test Case 2

    Input (stdin)
    8

    Expected Output
    Octagon
Solution

#include <stdio.h>
int main()
{
int a;
  scanf ("%d",&a);
  switch (a)
  {
    case 7: 
      printf ("Heptagon");
      break;
    case 8: 
      printf ("Octagon");
      break;
    case 9: 
      printf ("Nanogon");
      break;
    case 10: 
      printf ("Decagon");
      break;
    default: 
      printf ("Not Identified");
  }
  
            return 0;
}

2 comments:

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...