我必须输入整数并对每个整数进行运算。每个整数之间会用空格分隔,并且整数的个数没有定义,
因此输入可能是 1 23 45 80 或 21 32。
我厌倦了使用 cin,它不起作用,因为在空间上它会损坏。
我正在编写一个脚本,其中一部分会输出一个数字$ stats,即74.9,如果它小于100,那么如果不是它就会失败.我试过了
do stuff
done
echo $stats
if [ $stats -gt 100 ]; then
echo "PASS"
else
echo "FAIL"
fi
Run Code Online (Sandbox Code Playgroud)
但它失败了
72.4
./runme.sh: line 66: [: 72.4: integer expression expected
FAIL
Run Code Online (Sandbox Code Playgroud) 有没有办法检查整数是否在 C# 中包含某个数字?
例如:
我想检查7,当我输入17时,代码将返回1。当我输入28时,代码将返回0。
谢谢你
假设我有3个整数:
int a, b, c;
b = 25;
c = 10;
Run Code Online (Sandbox Code Playgroud)
现在我想要a25或10,但随机不是这样的:
a = b;
Run Code Online (Sandbox Code Playgroud)
我想要if语句中的内容:
a = b || c;
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现它?
我想将分裂整数分解为它们的因素.例如,如果记录总数为:
169 - ( 13 x 13 times)
146 - ( 73 x 2 times)
150 - ( 50 x 3 times)
175 - ( 25 x 7 times)
168 - ( 84 x 2 )
160 - ( 80 x 2 times)
Run Code Online (Sandbox Code Playgroud)
当它超过10k时 - 我想要1000上的所有东西当它超过10万时 - 我希望一切都在10k上
通过这种方式,我想要计算数字.怎么做到这一点?是否有任何Perl模块可用于这些类型的操作?
假设记录总数为10k.它应该分开1000x10倍; 不是100或10.
我可以使用sqrt功能.但这并不总是我所期待的.如果我给出输入146,我必须得到(73,2).
我的理解是python可以处理任意长度的整数.它很好地处理加法和乘法,但似乎与分裂分开.
>>> from decimal import Decimal, getcontext
>>> getcontext().prec=2**5
>>> ORIG_NUM=476939688738611836995535477357070857939902076027788232031989775824606225595773435668861833
>>> print(Decimal(ORIG_NUM)/7)
6.8134241248373119570790782479582E+88
>>> print("%.6f" % (Decimal(ORIG_NUM)/7))
68134241248373123068520468160885027682039120236463560535175757714209021725053511199096832.000000
Run Code Online (Sandbox Code Playgroud)
我不希望e符号因此getcontext().prec尝试.还有,%f丢弃小数?
>>> getcontext().prec=2**7
>>>QUOTIENT= (Decimal(476939688738611836995535477357070857939902076027788232031989775824606225595773435668861833)/7)
>>>print(QUOTIENT)
68134241248373119570790782479581551134271725146826890290284253689229460799396205095551690.428571428571428571428571428571428571429
>>>QUOTIENT*7
4.7693968873861185e+89
>>> Decimal(QUOTIENT)*7
Decimal('476939688738611861479643277126195193774273841655244923746230303999463152075374578393677824')
>>> print(Decimal(QUOTIENT)*7)
476939688738611861479643277126195193774273841655244923746230303999463152075374578393677824
>>> print(Decimal(QUOTIENT)*7)==ORIG_NUM
476939688738611861479643277126195193774273841655244923746230303999463152075374578393677824
False
Run Code Online (Sandbox Code Playgroud)
第二个问题是数字不匹配.
有关该主题的任何信息?
希望更好......
#include<iostream>
using namespace std;
int x;
int y;
int z;
int main ()
{
cout << "x=";
cin >> x;
z = x;
y = 0;
while(z > 0)
{
(z = z / 10);
(y = y + 1);
}
while(z < 0)
{
(z =- z);
(z = z / 10);
(y = y + 1);
}
cout << "cifre=" << y;
}
Run Code Online (Sandbox Code Playgroud)
它似乎对正整数有效,但不适用于负整数,我不明白为什么.谁能解释一下?它必须计算位数......
需要在整数名称前添加5位数0作为整数的记录号.它正在循环中使用,也在word文档中添加记录号.PLease提供任何解决方案.我已经尝试过以下事情,但没有按照以下方式工作
int recordnumber =1;
recordnumber.tostring("00000");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string[] stringArray1 = new string[2];
string[] stringArray2 = new string[2];
string[] stringArray3 = new string[2];
//ArrayList al = new ArrayList();
int customerId = 100000;
int customeraccount = 100001;
int accountnumber = 100000100;
int recordnumber = 1;
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
stringArray1[i] = …Run Code Online (Sandbox Code Playgroud) 我需要从一些Area eq加入3个整数
int sens1[]= {11,22,13,66,2};
int x= ?? // and here i need to join sens1[0], sens1[1] and sens1[2]
// so the X to be=112213 not like char, like integer value
Run Code Online (Sandbox Code Playgroud) 当我划分两个整数时,我正在尝试确定结果是否为整数.我怎么做?
float result;
int number1, number2;
cout<<"Give me number 1 and 2"<<endl;
cin>>number1;
cin>>number2;
result = number1 / number2;
if(result == int)
{
cout<<"The numbers can be devided"<<endl;
}else cout<<"The numbers can't be devided"<<endl;
Run Code Online (Sandbox Code Playgroud)
我得到错误,因为你不能这样做,有人能帮我一把吗?它让我烦恼,每个帖子都告诉我,如何检查输入是否为整数,而不是结果.我不关心输入,我想知道结果是否为整数.感谢帮助!
编辑:
所以我的函数看起来像这样:
int funkcijaDva()
{
int popizdobom = 0;
int tri = 3;
int tristo = 300;
int tritisoc = 3000;
float result;
for(; tristo!=tritisoc;tristo++)
{
result = (int)tristo / tri;
if(tri % tristo == 0)
{
popizdobom++;
}
}
return popizdobom;
}
Run Code Online (Sandbox Code Playgroud)
popizdobom的结果总是0 ...我做错了吗?编辑:让它工作......编译器出错了我猜...