0% found this document useful (0 votes)
14 views6 pages

Ropa

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Ropa

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Question 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ropa
{
class Program
{
static void Main(string[] args)
{
int num1, num2, num3;
Console.WriteLine("Enter the First number: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Second number: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Third number: ");
num3 = Convert.ToInt32(Console.ReadLine());

if (num1 > num2 && num1 > num3)


{
Console.WriteLine(num1 + " Is the biggest");

}
else
{
if (num2 > num1 && num2 > num3)
{
Console.WriteLine(num2 + " Is the biggest");

}
else
{
if (num3 > num1 && num3 > num2)
{
Console.WriteLine(num3 + " Is the biggest");
}
}
}
Console.ReadLine();

}
}

}
Question 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ropa
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number (0 to 999): ");
int number = Convert.ToInt32(Console.ReadLine());

string result = NumberToWords(number);


Console.WriteLine("The number " + number + " in words: " + result);
Console.ReadLine();
}

public static string NumberToWords(int number)


{
if (number == 0)
return "Zero";

string[] unitsMap = { "Zero", "One", "Two", "Three", "Four", "Five", "Six",


"Seven", "Eight", "Nine" };
string[] tensMap = { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty",
"Seventy", "Eighty", "Ninety" };
string[] teensMap = { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };

string words = "";

if (number >= 100)


{
words += unitsMap[number / 100] + " Hundred";
number %= 100;
if (number > 0)
words += " and ";
}

if (number >= 20)


{
words += tensMap[number / 10];
number %= 10;
if (number > 0)
words += " ";
}

if (number > 0)
{
if (number < 10)
words += unitsMap[number];
else
words += teensMap[number - 10];
}

return words;
}
}
}

Question 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ropa
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a positive integer (N): ");
int N = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Numbers not divisible by 3 and 7:");


for (int i = 1; i <= N; i++)
{
if (i % 3 != 0 && i % 7 != 0)
{
Console.Write(i + " ");
}
}

Console.ReadKey();
}
}

Question 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ropa
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a positive integer (N): ");
int N = int.Parse(Console.ReadLine());

int trailingZeroes = CountTrailingZeroes(N);


Console.WriteLine("Number of trailing zeroes in " + N + " is " +
trailingZeroes);
Console.ReadLine();
}

public static int CountTrailingZeroes(int n)


{
int count = 0;
for (int i = 10; n / i >= 1; i++)
{
if(n / i >= 1 && n % 10 == 0)
{
count++;
}
}
return count;
}
}

Question 5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ropa
{
class Program
{
static void Main(string[] args)
{
int[] array = { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };

int mostFrequent = FindMostFrequentElement(array);


int frequency = CountFrequency(array, mostFrequent);
Console.WriteLine("The most frequent element is " + mostFrequent + " occurs "
+ frequency + " times.");
Console.ReadLine();
}

public static int FindMostFrequentElement(int[] arr)


{
Dictionary<int, int> frequencyMap = new Dictionary<int, int>();

foreach (int num in arr)


{
if (frequencyMap.ContainsKey(num))
frequencyMap[num]++;
else
frequencyMap[num] = 1;
}

int maxFrequency = 0;
int mostFrequentElement = 0;

foreach (var kvp in frequencyMap)


{
if (kvp.Value > maxFrequency)
{
maxFrequency = kvp.Value;
mostFrequentElement = kvp.Key;
}
}

return mostFrequentElement;
}

public static int CountFrequency(int[] arr, int target)


{
int count = 0;
foreach (int num in arr)
{
if (num == target)
count++;
}
return count;
}
}
}

Question 6

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter three integers:");
int num1 = Convert.ToInt32(Console.ReadLine());
int num2 = Convert.ToInt32(Console.ReadLine());
int num3 = Convert.ToInt32(Console.ReadLine());

int maxOfTwo = GetMax(num1, num2);


int largestNumber = GetMax(maxOfTwo, num3);

Console.WriteLine("The largest number is: " + largestNumber);


Console.ReadLine();
}

public static int GetMax(int a, int b)


{
return a > b ? a : b;
}
}

Question 7

You might also like