0% found this document useful (0 votes)
39 views

Exercise # 2:: M Hadi Khan: 11305: PF Lab 12

The document contains code for two exercises, the first calculates the standard deviation of values in an array by taking the average, subtracting it from each value, squaring the results, taking the average of the squared values, and calculating the square root. The second program takes a future value, interest rate, and number of years as input and calculates the present value using the formula present value = future value / (1 + interest rate)^years.

Uploaded by

Hadi Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Exercise # 2:: M Hadi Khan: 11305: PF Lab 12

The document contains code for two exercises, the first calculates the standard deviation of values in an array by taking the average, subtracting it from each value, squaring the results, taking the average of the squared values, and calculating the square root. The second program takes a future value, interest rate, and number of years as input and calculates the present value using the formula present value = future value / (1 + interest rate)^years.

Uploaded by

Hadi Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

M HADI KHAN :

11305:

PF LAB 12:

EXERCISE # 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp96
{
class Program
{
public static void Main(String[] args)
{

double[] numArray = new double[5];

for (int i = 0; i < numArray.Length; i++)


{
Console.Write("Enter Value For " + i +
" : ");
numArray[i] =
double.Parse(Console.ReadLine());
}

Method(numArray);
Console.ReadLine();

}
public static void Method(double[] numArray)
{
double sum = 0;
double ave;
double length = numArray.Length;

Console.WriteLine();
Console.WriteLine();
for (int i = 0; i < length; i++)
{
sum = sum + numArray[i];
}

Console.WriteLine("Sum : " + sum);


ave = sum / length;
Console.WriteLine("Average : " + ave);

for (int i = 0; i < length; i++)


{
numArray[i] = numArray[i] - ave;
}
for (int i = 0; i < length; i++)
{
numArray[i] = numArray[i] * numArray[i];
}
sum = 0;
for (int i = 0; i < length; i++)
{
sum = sum + numArray[i];
}
ave = 0;
ave = sum / (length - 1);
double standard_daviation = Math.Sqrt(ave);
Console.WriteLine("Standard Daviation : " +
standard_daviation);
}
}
}
EXERCISE # 3:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp87
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter future value: ");
int f = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("enter annual interest rate: ");


double air = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("enter year: ");


int y = Convert.ToInt32(Console.ReadLine());

Console.WriteLine(PresentValue(f,air,y));
}
static double PresentValue(int f, double air, int y )
{
double p = f /Math.Pow ((1 + air),y);
return p;
}
}
}

You might also like