//Write a program to find the biggest number in n numbers without using arrays.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace biggestnumber
{
class Program
{
static void Main(string[] args)
{
int ntimes = 0,biggest_number=0,num=0;
Console.Write("How many times you want to enter the number : ");
ntimes = int.Parse(Console.ReadLine());
for (int i = 1; i <= ntimes; i++)
{
Console.Write("Enter {0} Number ",i);
num = int.Parse(Console.ReadLine());
if (biggest_number< num)
biggest_number = num;
}
Console.WriteLine();
Console.WriteLine("The biggest Number : " + biggest_number);
Console.ReadKey();
} } }
Sunday, 27 January 2013
//Write a program to take as input a number n and find the sum of all numbers from 1 to n.
//Eg. If input is 6 then output should be 1+2+3+4+5+6 = 21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace addtwonos
{
class Program
{
static void Main(string[] args)
{
int n = 0, total = 0, temp = 0;
Console.Write("Enter the n number : ");
n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
Console.Write("Enter the {0} number ", i);
temp = int.Parse(Console.ReadLine());
total = total + temp;
}
Console.WriteLine("The total of a number u entered is : " + total);
//total = Int32.Parse(Console.ReadLine());
Console.ReadKey();
}
}
}
Subscribe to:
Comments (Atom)