Tesco Interview Questions
Tesco Interview Questions
using System;
using System.Collections.Generic;
namespace Memory_understanding
{
public class UserMainCode
{
//Assume following return types while writing the code for this question.
public static int output1;
public static int letter(string input1)
{
int sum = 0;
char[] arra = input1.ToCharArray();
for (int i = 0; i < arra.Length; i++)
{
char char_a = arra[i];
int pos = getPosition(char_a);
sum = sum + fib(pos);
}
output1 = sum;
return output1;
}
public static int fib(int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
else
return fib(n - 1) + fib(n - 2);
}
public static int getPosition(char n)
{
char[] arr = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z'};
int position = 0;
for (int i = 0; i < 26; i++)
{
if (n == arr[i])
position = i;
}
return position;
}
}
class Main_class
{
public static void Main_()
{
Console.WriteLine(UserMainCode.letter("MAN"));
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
namespace Memory_understanding
{
public class UserMainCode
{
//Assume following return types while writing the code for this question.
public static int output1;
public static int letter(string input1)
{
int sum = 0;
char[] arra = input1.ToCharArray();
for (int i = 0; i < arra.Length; i++)
{
char char_a = arra[i];
int pos = getPosition(char_a);
sum = sum + fib(pos);
}
output1 = sum;
return output1;
}
public static int fib(int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
else
return fib(n - 1) + fib(n - 2);
}
public static int getPosition(char n)
{
char[] arr = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z'};
int position = 0;
for (int i = 0; i < 26; i++)
{
if (n == arr[i])
position = i;
}
return position;
}
}
class Main_class
{
public static void Main_()
{
Console.WriteLine(UserMainCode.letter("MAN"));
Console.ReadLine();
}
}
}
Comments
Post a Comment