C# Program to demonstrate that one function can be called multiple times.

/* C# Program to demonstrate that one function can be called multiple times. */
using System;
public class Demo
{
    public static int add(int a, int b)
    {
        int ans = 0;
        ans = a + b;
        return ans;
    }

    public static void Main(string[] args)
    {
        int one, two, ans;
        Console.WriteLine("Enter 2 numbers :");
        one = Convert.ToInt32(Console.ReadLine());
        two = Convert.ToInt32(Console.ReadLine());
        ans = add(one, two);
        Console.WriteLine("\nAddition of {0} & {1} : {2}\n\n", one, two, ans);
        ans = 0;
        Console.WriteLine("Enter 2 numbers again :");
        one = Convert.ToInt32(Console.ReadLine());
        two = Convert.ToInt32(Console.ReadLine());
        ans = add(one, two);
        Console.WriteLine("\nAddition of {0} & {1} : {2}\n\n", one, two, ans);
        Console.ReadLine();
    }
}

Output :
Enter 2 numbers :

23
2

Addition of 23 & 2 : 25

Enter 2 numbers again :

22
25

Addition of 22 & 25 : 47



Leave a comment