QANTLER TECHNOLOGIES – Fresher Interview Questions with Answers – Session – 3

This blog explains about QANTLER TECHNOLOGIES – Fresher Interview Questions with Answers – Session – 3. They are explained clearly well below :
                                                  We have already discussed about some questions in the previous blog . Some of the frequently asked questions are : 

 ___________________________________________________________________

1. Write a program to print the days of the week based on the input given

(eg: 3 print Tuesday )

/**

* C program to print day name of week

*/

 #include <stdio.h>

 int main()

{

    int week;

     /* Input week number from user */

    printf(“Enter week number (1-7): “);

    scanf(“%d”, &week);

      if(week == 1)

    {

        printf(“Monday”);

    }

    else if(week == 2)

    {

        printf(“Tuesday”);

    }

    else if(week == 3)

    {

        printf(“Wednesday”);

    }

    else if(week == 4)

    {

        printf(“Thursday”);

    }

    else if(week == 5)

    {

        printf(“Friday”);

    }

    else if(week == 6)

    {

        printf(“Saturday”);

    }

    else if(week == 7)

    {

        printf(“Sunday”);

    }

    else

    {

        printf(“Invalid Input! Please enter week number between 1-7.”);

    }

     return 0;

}

_______________________________________________________________________________

2. Write a java program to find the factorial of given number using recursion

class FactorialDemo2{

   public static void main(String args[]){

      int factorial = fact(4);

      System.out.println(“Factorial of 4 is: “+factorial);

   }

   static int fact(int n)

   {

       int output;

       if(n==1){

         return 1;

       }

       //Recursion: Function calling itself!!       output = fact(n-1)* n;       return output;   }}

Output:

Factorial of 4 is: 24

______________________________________________________________________________

3. Write a Java Program to reverse a given number ? 

  1. importutil.Scanner;
  2. classReverseNumber
  3. {
  4.  publicstatic void main(String args[])
  5.  {
  6.     intn, reverse = 0;
  7.        
  8. out.println(“Enter an integer to reverse”);
  9.     Scanner in = new Scanner(System.in);
  10.     n = in.nextInt();
  11.        
  12.     while(n != 0)
  13.     {
  14.         reverse = reverse * 10;
  15.         reverse = reverse + n%10;
  16.         n = n/10;
  17.     }
  18.      
  19. out.println(“Reverse of the number is ” + reverse);
  20.  }

}

_____________________________________________________________________________________

REFERENCES : 

QANTLER TECHNOLOGIES – Fresher Interview Questions with Answers – Session – 1  & 2

https://payilagam.com/blogs/qantler-technologies-fresher-interview-questions-with-answers-session-1/

https://payilagam.com/blogs/qantler-technologies-fresher-interview-questions-with-answers-session-2/

https://codeforwin.org/2015/05/c-program-to-print-week-name.html

https://beginnersbook.com/2014/01/java-program-to-find-factorial-of-a-given-number-using-recursion/

https://www.programmingsimplified.com/java/source-code/java-program-reverse-number