Program to add two numbers by accepting input from the user:
----------------------------------------------------
Program:
using System;
namespace AddTwoNumbers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the first number: ");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the second number: ");
int num2 = int.Parse(Console.ReadLine());
int sum = num1 + num2;
Console.WriteLine("The sum of {0} and {1} is {2}.", num1, num2, sum);
}
}
}
----------------------------------------------------
#basicprograms
----------------------------------------------------
Program:
using System;
namespace AddTwoNumbers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the first number: ");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the second number: ");
int num2 = int.Parse(Console.ReadLine());
int sum = num1 + num2;
Console.WriteLine("The sum of {0} and {1} is {2}.", num1, num2, sum);
}
}
}
----------------------------------------------------
#basicprograms
here's an example of a TypeScript program that calculates the factorial of a given number:
function factorial(num: number): number {
if (num === 0) {
return 1;
} else {
return num * factorial(num - 1);
}
}
const number = 5 // replace with the number you want to find the factorial of
const result = factorial(number);
console.log(The factorial of ${number} is ${result});
function factorial(num: number): number {
if (num === 0) {
return 1;
} else {
return num * factorial(num - 1);
}
}
const number = 5 // replace with the number you want to find the factorial of
const result = factorial(number);
console.log(The factorial of ${number} is ${result});