实验1-1 问候 (20分)
输出问候:Hello!What's your name? 从键盘输入名字,然后输出欢迎信息。
输入格式:
请在这里写输入姓名。例如: GaiFuShuai
输出格式:
请在这里描述输出,例如:
Hello!What's your name?
GaiFuShuai,Welcome to learn OOP using C++!
输入样例:
BaiFuMei
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace first
{
class Program
{
static void Main(string[] args)
{
string name;
name=Console.ReadLine();
Console.WriteLine("Hello!What's your name?\n"+name + ',' + "Welcome to learn OOP using C++!");
}
}
}
实验1-2 Say Hello to Integers (20分)
Say hello to integers? Yes! 你没看错! 现在我们来向整数说“你好~” 本题读入两个整数,然后输出对她们的问候语。
输入格式:
在一行中给出两个绝对值不超过32767的整数A和B,两数之间有一个空格
输出格式:
在一行中输出 "Hello, A and B!" (其中A和B用实际输入的整数代替)
输入样例:
1949 2015
输出样例:
Hello, 1949 and 2015!
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace first
{
class Program
{
static void Main(string[] args)
{
List<int> intlist = new List<int>(2);
string str = Console.ReadLine();
string[] sarr = str.Split(' ');
foreach(string item in sarr)
{
intlist.Add(int.Parse(item));
}
int[] arr= intlist.ToArray();
Console.WriteLine("Hello, {0} and {1}!",arr[0],arr[1]);
System.Console.ReadKey();
}
}
}
实验1-3 jmu-python-求圆面积 (20分)
输入一个数值表示圆的半径,求相应圆的面积。圆周率要求使用math库中的pi常量。
输入格式:
输入数值型数据,例如:1.5
输出格式:
输出圆面积,要求小数点后保留两位,例如:7.07
输入样例:
在这里给出一组输入。例如:
1.5
输出样例:
在这里给出相应的输出。例如:
7.07
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace first
{
class Program
{
static void Main(string[] args)
{
float radius = float.Parse(Console.ReadLine());
double s = Math.Round(Math.PI * radius * radius,2);
Console.WriteLine(s);
System.Console.ReadKey();
}
}
}
实验1-4 计算摄氏温度 (20分)
给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C。计算公式:C=5×(F−32)/9。题目保证输入与输出均在整型范围内。
输入格式:
输入在一行中给出一个华氏温度。
输出格式:
在一行中按照格式“Celsius = C”输出对应的摄氏温度C的整数值。
输入样例:
150
输出样例:
Celsius = 65
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace first
{
class Program
{
static void Main(string[] args)
{
int F = int.Parse(Console.ReadLine());
int C = 5 * (F - 32) / 9;
Console.WriteLine("Celsius = {0}", C);
System.Console.ReadKey();
}
}
}
实验1-5 两个数的简单计算器 (20分)
本题要求编写一个简单计算器程序,可根据输入的运算符,对2个整数进行加、减、乘、除或求余运算。题目保证输入和输出均不超过整型范围。
输入格式:
输入在一行中依次输入操作数1、运算符、操作数2,其间以1个空格分隔。操作数的数据类型为整型,且保证除法和求余的分母非零。
输出格式:
当运算符为+、-、*、/、%时,在一行输出相应的运算结果。若输入是非法符号(即除了加、减、乘、除和求余五种运算符以外的其他符号)则输出ERROR。
输入样例1:
-7 / 2
输出样例1:
-3
输入样例2:
3 & 6
输出样例2:
ERROR
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace first
{
class Program
{
static void Main(string[] args)
{
string operation = Console.ReadLine();
string[] oarr = operation.Split(' ');
int first = int.Parse(oarr[0]);
char Operator = char.Parse(oarr[1]);
int second = int.Parse(oarr[2]);
switch (Operator)
{
case '+':
Console.WriteLine(first+second);
break;
case '-':
Console.WriteLine(first - second);
break;
case '*':
Console.WriteLine(first * second);
break;
case '/':
Console.WriteLine(first / second);
break;
case '%':
Console.WriteLine(first % second);
break;
default:
Console.WriteLine("ERROR");
break;
}
System.Console.ReadKey();
}
}
}
698

被折叠的 条评论
为什么被折叠?



