当前位置:网站首页>C simple question one
C simple question one
2022-07-07 23:34:00 【Bobo in summer】
1. Output in reverse order
string aa = Console.ReadLine();
string bb="";
for (int i = aa.Length-1; i >= 0; i--)
{
bb += aa[i];
}
Console.WriteLine(bb);
2. The length of three sides of a triangle is known a,b,c, The three sides are input by the user , Programming judgment a、b、c Whether the value of constitutes a triangle , If it forms a triangle , Then calculate and output the area of the triangle , Otherwise output “ Can't make a triangle ” Calculate the area of the triangle
double a =double.Parse(Console.ReadLine());
double b = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
double s = 0;
double area = 0;
if ((a + b > c) && (a + c > b) && (b + c > a))
{
Console.WriteLine(" Sure ");
s = 0.5 * (a + b + c);
area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
else
{
Console.WriteLine(" Can't form a triangle ");
}
3. Enter a string str1, Delete str1 All of them 0-9 The number character of , Output the processed string
string aa = Console.ReadLine();
string bb = "";
for (int i = 0; i < aa.Length; i++)
{
if (!char.IsDigit(aa[i]))
{
bb += aa[i];
}
}
Console.WriteLine(bb);
4. Input 10 Number , Calculate average , Count the number of data below the average and output the data below the average
Console.Write(" Please enter ten integers : Press enter Continue to enter ");
int[] a = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
int b = 0;
for (int j = 0; j < 10; j++)
{
b += a[j];
}
float c = b / 10;
int count = 0;
for (int k = 0; k < 10; k++)
{
if (a[k] < c)
{
Console.Write("{0},", a[k]);
count++;
}
}
Console.WriteLine(" share {0} A number less than the average ", count);
5. Input 10 Number , Calculate average , Count the number of data higher than the average value and output the data higher than the average value
int[] srr = new int[10] {
1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
double sum = 0;
double ave = 0;
int count = 1;
for (int i = 0; i < 10; i++)
{
sum += srr[i];
count++;
}
ave = sum / count;
string aa = "";
int count1 = 1;
for (int j = 0; j < 10; j++)
{
if (srr[j] > ave)
{
aa += srr[j]+" ";
count1++;
}
}
Console.WriteLine("{0} ",aa);
Console.WriteLine(count1);
6. Enter some integers , Find the largest number , Secondary maximum , minimum value , Secondary minimum
int[] srr = new int[10];
for (int a = 0; a < 10; a++)
{
srr[a] =int.Parse( Console.ReadLine());
}
int temp = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 9-i; j++)
{
if (srr[j] > srr[j + 1])
{
temp = srr[j];
srr[j] = srr[j + 1];
srr[j + 1] = temp;
}
}
}
Console.WriteLine("{0},{1},{2},{3}",srr[9],srr[8],srr[0],srr[1]);
7. Enter several ordered positive integers , For the same data, only one , Output retained data . for example , The input data is : 2,2,2,3,3,4,5,5,6,6,8,8,9,9,9,10,10,10 The final output is : 2,3,4,5,6,8,9,10.
string str1=Console.ReadLine();;
string ret = "";
for (int i = 0; i < str1.Length; i++)
{
char ch = str1[i];
if (ret.IndexOf(ch.ToString()) >= 0)
{
continue;
}
ret = ret + ch.ToString();
}
Console.WriteLine(ret);
Console.ReadLine();
8. Enter a string , Judge if it's all numbers , Convert it to an integer , If other symbols are included , Give an error .
string aa=Console.ReadLine();
for (int i = 0; i < aa.Length; i++)
{
if (!char.IsDigit(aa[i]))
{
Console.WriteLine("error");
break;
}
else
Console.WriteLine(aa);
break;
}
9. Input 20 A positive integer , Count and output the number of odd and even numbers , And classify and output all odd and even numbers .
int[] arr = new int[10] {
1,2,3,4,5,6,7,8,9,10 };
string aa="";
string bb="";
int count1 = 1;
int count2 = 1;
for (int i = 0; i < 10; i++)
{
if (arr[i] % 2 == 0)
{
aa += arr[i]+" ";
count1++;
}
else
{
bb += arr[i]+" ";
count2++;
}
}
Console.WriteLine(aa);
Console.WriteLine(count1);
Console.WriteLine(bb);
Console.WriteLine(count2);
10. Input from terminal 5 Number , Output from small to large .
int[] a = new int[6];
Console.WriteLine(" Please enter six numbers :");
for (int l = 0; l < 6; l++)
{
a[l] = int.Parse(Console.ReadLine());
}
for (int j = 0; j < 6; j++)
{
for (int i = 0; i<5; i++)
{
int temp;
if (a[i] > a[i+1])
{
temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
}
}
}
for (int k = 0; k < 6; k++)
{
Console.Write(" " + a[k]);
}
using System.Collections;
ArrayList list = new ArrayList();
for (int i = 0; i < 5; i++){
list.Add(int.Parse(Console.ReadLine()));
}
list.Sort();
for (int i = 0; i < list.Count; i++) {
Console.WriteLine(list[i]);
}
11. Read in... From the keyboard 20 Data into array , Count the number of negative numbers , And calculate the sum of these negative numbers .
int[] a = new int[20];
Console.WriteLine(" Please enter twenty numbers :");
for (int i = 0; i < 20; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
int count = 0;
double sum = 0;
for (int i = 0; i < 20; i++)
{
if (a[i] < 0)
{
count++;
sum += a[i];
}
}
Console.WriteLine(" Number :{0} Negative numbers and :{1}", count, sum);
12. seek n within ( barring n) Can't be 2 and 5 to be divisible by ( Can be 2 perhaps 5 Divisible but not divisible at the same time ) The square root of the sum of all natural numbers s,n Input from keyboard .
Console.WriteLine(" Please enter n");
int n = int.Parse(Console.ReadLine());
int sum = 0;
for(int i=0;i<n;i++)
{
if(i%2!=0&&i%5!=0)
{
sum += i;
}
}
double s = Math.Sqrt(sum);
Console.WriteLine(s);
random Generate 10 Number , Sort from small to large , Output max min , And the rest , Find the sum of the remaining numbers , Average .
public static void avee()
{
int[] srr = new int[10];
Random shuzu = new Random();
for (int i = 0; i < 10; i++)
{
srr[i]= shuzu.Next(60, 100);
}
//for (int i = 0; i < 10; i++)
//{
// srr[i] =int.Parse( Console.ReadLine());
//}
int m;
string ssss = "";
double ave;
double sum = 0;
for (int n = 0; n < 10; n++)
{
for (int j = 0; j < 9 - n; j++)
{
if (srr[j] > srr[j + 1])
{
m = srr[j];
srr[j] = srr[j + 1];
srr[j + 1] = m;
}
}
}
for(int i=1;i<srr.Length-1;i++)
{
ssss += srr[i]+" ";
sum += srr[i];
}
ave = sum / 8;
Console.WriteLine(" The maximum value is {0}", srr[9]);
Console.WriteLine(" The minimum value is {0}", srr[0]);
Console.WriteLine(" and :{0} Average {1}",sum,ave);
Console.WriteLine(ssss);
}
avee();
边栏推荐
- 家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
- ESP at installation esp8266 and esp32 versions
- [stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
- Happy gathering time
- LeeCode -- 6. Zigzag transformation
- USB (XV) 2022-04-14
- Lm12 rolling heikin Ashi double K-line filter
- System design overview
- LDO穩壓芯片-內部框圖及選型參數
- Spark 离线开发框架设计与实现
猜你喜欢
云原生正在吞噬一切,开发者该如何应对?
MATLAB signal processing [Q & A essays · 2]
Extended tree (I) - graphic analysis and C language implementation
包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
B_ QuRT_ User_ Guide(36)
RE1 attack and defense world reverse
B_QuRT_User_Guide(36)
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
B_QuRT_User_Guide(38)
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
随机推荐
SLAM面试总结
违法行为分析1
Coreseek:第二步建索引及測试
USB (XVI) 2022-04-28
产业共融新势能,城链科技数字峰会厦门站成功举办
Summary of common methods of object class (September 14, 2020)
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
sql 数据库执行问题
Unity3d learning notes 4 - create mesh advanced interface
FreeLink开源呼叫中心设计思想
IDEA 2021.3. X cracking
三问TDM
The 19th Zhejiang Provincial College Programming Contest 2022 f.easyfix chairman tree
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
MySQL Index Optimization Practice II
B_QuRT_User_Guide(36)
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
Have all the fresh students of 2022 found jobs? Is it OK to be we media?
HDU 4747 Mex「建议收藏」