Virtusa Polaris Interview Question for Freshers – Part – III

Virtusa Polaris Interview Question  for Freshers – Part – III 

This blog explains about Virtusa Polaris Interview Question  for Freshers – Part – III especially for the freshers including questions for programming .

                           We have already discussed about some questions in the previous blogs( Virtusa Polaris Interview Question – Part – I and II  ). Some of the few are illustrated below :

REFERENCES : ( Virtusa Polaris Interview Question – Part – I and II  )

 https://payilagam.com/blogs/virtusa-polaris-interview-question-part-i/

https://payilagam.com/blogs/virtusa-polaris-interview-question-part-ii/

_____________________________________________________

1. Write a program to find the factorial of the given number .

The factorial of a positive number n is given by:

factorial of n (n!) = 1*2*3*4….n

The factorial of a negative number doesn’t exist. And, the factorial of 0 is 1, 0! = 1

Example:

Factorial of a Number

#include <stdio.h>

int main()

{    int n, i;   

unsigned long long factorial = 1;    

printf(“Enter an integer: “);   

scanf(“%d”,&n);    

// show error if the user enters a negative integer   

if (n < 0)        printf(“Error! Factorial of a negative number doesn’t exist.”);    

else   

{       

                for(i=1; i<=n; ++i)       

               {           

                factorial *= i;              // factorial = factorial*i;       

                }       

                 printf(“Factorial of %d = %llu”, n, factorial);   

                }    

                 return 0;

                  }

Output

Enter an integer:

10 Factorial of 10 = 3628800

_______________________________________________________________________________

2. Write a program for Prefix to Postfix Conversion

Prefix : 

  An expression is called the prefix expression if the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).

Example :

*+AB-CD (Infix : (A+B) * (C-D) )

Postfix:

An expression is called the postfix expression if the operator appears in the expression after the operands. Simply of the form (operand1 operand2 operator).

Example :

AB+CD-* (Infix : (A+B * (C-D) )

Given a Prefix expression, convert it into a Postfix expression.

Conversion of Prefix expression directly to Postfix without going through the process of converting them first to Infix and then to Postfix is much better in terms of computation and better understanding the expression (Computers evaluate using Postfix expression).

Examples:

1. Input : Prefix :  *+AB-CD

   Output :Postfix : AB+CD-*

  Explanation :

  Prefix to Infix :  (A+B) * (C-D)    

 Infix to Postfix :  AB+CD-* 

2. Input :  Prefix :  *-A/BC-/AKL

   Output : Postfix : ABC/-AK/L-*

   Explanation :

   Prefix to Infix :  A-(B/C)*(A/K)-L             

   Infix to Postfix : ABC/-AK/L-*

_______________________________________________________________________________________