Last active
April 4, 2016 19:54
-
-
Save dogancankilment/d1199712abee322b228b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Special | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int counter = 0; | |
int result = 0; | |
int tmp; // tmp used for input | |
List<int> numbers = new List<int>(); | |
while (counter < 25) | |
{ | |
Console.Write("Enter a Number : "); | |
string input = Console.ReadLine(); | |
if (!string.IsNullOrEmpty(input)) | |
{ | |
// ofcourse if not tmp isString | |
tmp = int.Parse(input); | |
if (tmp >= 0) | |
{ | |
if (IsOdd(tmp)) | |
{ | |
// only odd numbers added into list | |
numbers.Add(tmp); | |
} | |
counter += 1; | |
} | |
else | |
{ | |
Console.Write("Please enter positive number"); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Please write some number"); | |
} | |
} | |
foreach (int i in numbers) | |
{ | |
result += (int)Math.Pow(i, 2); | |
} | |
// finally | |
Console.WriteLine(result); | |
} | |
public static bool IsOdd(int value) | |
{ | |
return value % 2 != 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment