902. The level of educational achievements

 

Determine the level of educational achievements for the pupil (elementary, average, sufficient, high) according to the given grade (from 1 to 12).

 

Input. One number that is a grade for the pupil.

 

Output. Print Initial for elementary level (grade from 1 to 3), Average for average level (grade from 4 t  6), Sufficient for sufficient level (grade from 7 to 9) and High for high level (grade from 10 to 12).

 

Sample input

Sample output

12

High

 

 

SOLUTION

conditional statement

 

Algorithm analysis

To solve the problem, implement the conditional statement.

 

Algorithm realization

Read the grade of the student. Print the answer by implementing the conditional operator.

 

scanf("%d",&n);

if (n <= 3) printf("Initial\n"); else

if (n <= 6) printf("Average\n"); else

if (n <= 9) printf("Sufficient\n"); else

            printf("High\n");

 

Algorithm realization – switch

 

#include <stdio.h>

 

int n;

 

int main(void)

{

  scanf("%d", &n);

 

  switch (n)

  {

    case 1:

    case 2:

    case 3:

      printf("Initial\n");

      break;

    case 4:

    case 5:

    case 6:

      printf("Average\n");

      break;

    case 7:

    case 8:

    case 9:

      printf("Sufficient\n");

      break;

    default:

      printf("High\n");

  }

 

  return 0;

}

 

Algorithm realization – switch optimized

 

#include <stdio.h>

 

int n;

 

int main(void)

{

  scanf("%d", &n);

  n = (n - 1) / 3;

 

  switch (n)

  {

    case 0:

     printf("Initial\n");

      break;

    case 1:

      printf("Average\n");

      break;

    case 2:

      printf("Sufficient\n");

      break;

    default:

     printf("High\n");

  }

 

  return 0;

}

 

Java realization

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int n = con.nextInt(); 

    if (n <= 3) System.out.println("Initial"); else

    if (n <= 6) System.out.println("Average"); else

    if (n <= 9) System.out.println("Sufficient"); else

                System.out.println("High");

    con.close();

  }

}

 

Java realization switch

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int n = con.nextInt();

    switch (n)

    {

      case 1:

      case 2:

      case 3:

        System.out.println("Initial");

        break;

      case 4:

      case 5:

      case 6:

        System.out.println("Average");

        break;

      case 7:

      case 8:

      case 9:

       System.out.println("Sufficient");

        break;

      default:

       System.out.println("High");

    }

    con.close();

  }

}