11. Write a program to find the sum of all elements in an array.

Required Input:

[1, 2, 3, 4, 5]

Expected Output:

Sum: 15

Code In Typescript

let numbers: number[]; // Assign an array of numbers function sumArray(arr: number[]): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

12. Write a program to determine if a given year is a leap year.

Required Input:

2024

Expected Output:

2024 is a leap year.

Code In Typescript

function isLeapYear(year: number): void { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

13. Create an interface Person with properties name and age. Create an object using this interface.

Required Input:

Name: "Alice", Age: 25

Expected Output:

Name: Alice, Age: 25

Code In Typescript

interface Person { // Define properties } let person: Person = { name: "Alice", age: 25 }; console.log(Name: ${person.name}, Age: ${person.age});

Run Code?

Click Run Button to view compiled output

14. Write a program to find the largest number in an array.

Required Input:

[10, 25, 5, 30, 15]

Expected Output:

Largest number: 30

Code In Typescript

let numbers: number[]; // Assign an array of numbers function findLargest(arr: number[]): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

15. Write a TypeScript function to concatenate two strings.

Required Input:

String 1: "Hello", String 2: "World"

Expected Output:

HelloWorld

Code In Typescript

function concatenateStrings(str1: string, str2: string): string { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

16. Create a tuple with a string and a number, and print the values.

Required Input:

String: "Apple", Number: 10

Expected Output:

Item: Apple, Quantity: 10

Code In Typescript

let item: [string, number]; // Your logic here

Run Code?

Click Run Button to view compiled output

17. Write a program to print the first 10 numbers in the Fibonacci sequence.

Required Input:

None

Expected Output:

0 1 1 2 3 5 8 13 21 34

Code In Typescript

function fibonacci(n: number): void { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

18. Write a program to calculate the average of an array of numbers.

Required Input:

[10, 20, 30, 40, 50]

Expected Output:

Average: 30

Code In Typescript

let numbers: number[]; function calculateAverage(arr: number[]): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

19. Create a function that checks if a given string is a palindrome.

Required Input:

"madam"

Expected Output:

"madam" is a palindrome

Code In Typescript

function isPalindrome(str: string): void { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

20. Write a function to convert a temperature from Celsius to Fahrenheit.

Required Input:

25

Expected Output:

Temperature in Fahrenheit: 77

Code In Typescript

function celsiusToFahrenheit(celsius: number): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

ad vertical

2 of 3