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

### (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.  }

}

_____________________________________________________________________________________