// Write a program that prints
//*
//**
//***
//****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Monday, 28 January 2013
// Write a program to take as input your name and print “Hello name”.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string name = string.Empty;
Console.WriteLine("Enter your Name:");
name = Console.ReadLine();
Console.Clear();
Console.Write("\n");
Console.WriteLine("Hello " + name);
Console.ReadKey();
}
}
}
// Write a program to find out m % n without using the % operator.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prog7
{
class Program
{
static void Main(string[] args)
{
int n = 0, m = 0, def=0;
Console.WriteLine("Enter M value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Nvalue");
n = int.Parse(Console.ReadLine());
if (n == 1)
Console.WriteLine("Result " +def);
else
{
while (m > 1)
{
m = m - n;
//Once it meet such a condition that m become lesser then n that's mean now we can't devide m number through n
if (m < n)
break;
}
//Moving to the next line
Console.WriteLine();
//Printing the biggest number from n number
Console.WriteLine(" Result: " + m);
}
//Waiting for any keypress
Console.ReadKey();
}
}
}
// Write a program to find out m / n without using the / operator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prog6
{
class Program
{
static void Main(string[] args)
{
int n = 0, m = 0, d = 0;
Console.WriteLine("Enter M value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Nvalue");
n = int.Parse(Console.ReadLine());
if (n == 1)
Console.WriteLine("Result" + m);
else
{
while (m > 1)
{
m = m - n;
d++;
}
//Moving to the next line
Console.WriteLine();
//Waiting for any keypress
Console.ReadKey();
}
}
}
}
// Write the programs to print the even numbers between 1 to 100.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace evennum
{
class Program
{
static void Main(string[] args)
{
int n ;
{
Console.WriteLine("the even numbers between 1 to 100 are :");
for (n = 1; n <= 100; n++)
if(n%2==0)
//while (n <= 100)
Console.WriteLine(n);
Console.ReadKey();
}
}
}
}
Sunday, 27 January 2013
//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();
} } }
//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:
Posts (Atom)