C#中,编写控制台应用程序项目,读入一组整数(以输入0结束)分别求出奇偶数之和

如题所述

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

string strtemp = Console.ReadLine();

Console.WriteLine("奇数和:{0}",jisuanjishuhe(strtemp));
Console.WriteLine("偶数和:{0}", jisuanoushuhe(strtemp));
Console.WriteLine("按回车退出");
Console.ReadLine();
}

static int jisuanjishuhe(string str)
{
int temp=0;
foreach (char c in str)
{
int i=(Convert.ToInt32(c)-48);
if ( i% 2 != 0)
{
temp += i;
}
}

return temp;
}

static int jisuanoushuhe(string str)
{
int temp = 0;
foreach (char c in str)
{
int i = (Convert.ToInt32(c) - 48);
if (i % 2 == 0)
{
temp += i;
}
}

return temp;
}
}
}

------------------
写代码辛苦,采纳吧
温馨提示:答案为网友推荐,仅供参考