Pages

Friday, 12 October 2012

Write a program in C# that calls a method to find the square of 10

Write a program in C# that calls a method to find the square of 10

Description:
In this post we are going to learn calling of  a method
  .
Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Square
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            string data = "";
            Console.WriteLine("Enter Number :");
            data=Console.ReadLine();
            a = int.Parse(data);
            int n = sqrt(a);
            Console.WriteLine("Square is:"+n);
            Console.ReadLine();
        }
        static int sqrt(int x)
        {
            int i = x;
            int b = i * i;
            return b;
        }
    }

Demo:
Write a program in C# that calls a method to find the square of 10
Write a program in C# that calls a method to find the square of 10





No comments:

Post a Comment