当前位置:网站首页>C simple question 2
C simple question 2
2022-07-07 23:34:00 【Bobo in summer】
13. 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);
14. Input 1~7 A number between , Output its corresponding day of the week . For example, the input 1 Output Monday.
Console.WriteLine(" Please enter 1-7 Number between :");
int n = int.Parse(Console.ReadLine());
switch(n%10)
{
case 1: Console.WriteLine("Monday");
break;
case 2:
Console.WriteLine("Tuesday");
break;
case 3:
Console.WriteLine("Wednesday");
break;
case 4:
Console.WriteLine("Thursday");
break;
case 5:
Console.WriteLine("Friday");
break;
case 6:
Console.WriteLine("Saturday");
break;
case 7:
Console.WriteLine("Sunday");
break;
default:Console.WriteLine(" There is an error in your input !");
break;
}
15. The single digit is 8 And can be 4 Divide but not be 7 How many two digit natural numbers are there in total , Number of Statistics , And output these numbers .
int count = 0;
for(int i=10;i<100;i++)
{
if(i%10==8&&i %4==0&&i%7!=0)
{
Console.Write("{0} ", i);
count++;
}
}
Console.WriteLine(" share {0} individual ",count);
16. Enter a string , use foreach Statement to calculate the length of the input string , And display the length .
Console.WriteLine(" Please enter a string :");
string st = Console.ReadLine();
int count = 0;
foreach(char c in st)
{
Console.Write("{0} ",c);
count++;
}
Console.WriteLine(" The length is :{0}",count);
17. Input 7 Number , Count the positive numbers respectively 、 negative 、 The number of zeros .
int[] marry = new int[7];
for (int i = 0; i < marry.Length; i++)
{
marry[i] = int.Parse(Console.ReadLine());
}
int zs = 0;
int fs = 0;
int zero = 0;
for (int i = 0; i < marry.Length; i++)
{
if (marry[i] > 0)
zs++;
else if (marry[i] < 0)
fs++;
if (marry[i] == 0)
zero++;
}
Console.Write(" Positive numbers have {0} individual , Negative numbers have {1} individual ,0 Yes {2} individual ", zs, fs, zero);
18. Calculation :1/2+2/3-3/4+4/5…… front 50 term .
double sum = 0;
for (double i = 1; i <= 50; i++)
{
sum += Math.Pow(-1, i + 1) * i / (i + 1);
}
Console.WriteLine("1/2+2/3-3/4+4/5…… front 50 Items for {0}", sum);
Console.ReadLine();
19. Fei's sequence is A.D 13 Invented by the mathematician fiboracci in the th century . namely :1,2,3,5,8,13,21,34,55,89,……, Output ratio 144 The big one, the smallest one .
int a = 1;
int b = 2;
int c = 3;
while (c < 144)
{
a = b;
b = c;
c = a + b;
}
Console.WriteLine(c+b);
20. Input some integers from the terminal , Find out more than 0 Number of numbers , And output these numbers and their average .
Console.WriteLine(" Please enter some integers :");
int[] a = new int[5];
for (int i = 0; i < a.Length; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
double sum = 0;
double avg = 0;
int count = 0;
for(int i=0;i<a.Length;i++)
{
if (a[i] > 0)
{
sum += a[i];
count++;
avg = sum / count;
}
}
Console.WriteLine(" The average value is {0}",avg);
21. Receive a real number entered by the user N, The absolute value of the real number is calculated and output by programming without using the function of calculating the absolute value .
Console.WriteLine(" Please enter a positive integer N:");
int N = int.Parse(Console.ReadLine());
int a;
if (N ==0)
Console.WriteLine("0 No absolute value !");
else if (N > 0)
Console.WriteLine("N The absolute value of is :{0}", N);
else
Console.WriteLine("N The absolute value of is :{0}", N * (-1));
. Receive a positive integer entered by the user N, seek 1-2+3-4…+N And output .
Console.WriteLine(" Please enter a positive integer N:");
int a = int.Parse(Console.ReadLine());
double sum = 0;
for(int i=0;i<=a;i++)
{
sum += Math.Pow(-1,i+1)*i;//( base number , Power number )
}
Console.WriteLine(" seek 1-2+3-4…+N Value :{0}", sum);
23. Receive a positive integer entered by the user N, Calculation 1 To N The cube and .
Console.WriteLine(" Please enter a positive integer :");
int a = int.Parse(Console.ReadLine());
double sum = 0;
for(int i=0;i<=a;i++)
{
sum += i * i*i ;
}
Console.WriteLine(" Cube sum is :{0}",sum);
24. Receive two numbers entered by the user , Judge whether two numbers can be divisible .
Console.WriteLine(" Please enter two numbers :");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
if (a % b == 0||b%a==0)
{
Console.WriteLine(" aliquot ");
}
else
Console.WriteLine(" Not divisible ");
边栏推荐
- B_ QuRT_ User_ Guide(38)
- USB (XVII) 2022-04-15
- USB (XIV) 2022-04-12
- Fibonacci number of dynamic programming
- Illegal behavior analysis 1
- Design and implementation of spark offline development framework
- Sequence of entity layer, Dao layer, service layer and controller layer
- sql 数据库执行问题
- VS扩展工具笔记
- 2021icpc Shanghai h.life is a game Kruskal reconstruction tree
猜你喜欢

S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption

SAP HR奖罚信息导出

13、 System optimization

Live server usage

re1攻防世界逆向

UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)

Markdown

生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
![给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」](/img/21/2e99dd6173ab4925ec22290cd4a357.png)
给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」

B_QuRT_User_Guide(36)
随机推荐
给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」
In the field of software engineering, we have been doing scientific research for ten years!
USB (XVIII) 2022-04-17
B_ QuRT_ User_ Guide(40)
【7.4】25. K 个一组翻转链表
LDO稳压芯片-内部框图及选型参数
PCI-Express接口的PCB布线规则
windows设置redis开启自动启动
Markdown
PHP uses Alibaba cloud storage
LDO voltage stabilizing chip - internal block diagram and selection parameters
The 19th Zhejiang Provincial College Programming Contest 2022 f.easyfix chairman tree
Live server usage
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
Coreseek: the second step is index building and testing
B_ QuRT_ User_ Guide(38)
B_ QuRT_ User_ Guide(36)
Explain
SAP HR 社会工作经历 0023
Live-Server使用