我试图找到我已经输入到程序中的两个向量(vector1,vector2)的欧几里得和。我试着用while循环来做这件事,但是由于某些原因,它不会产生正确的结果。有没有人能告诉我我的代码哪里出了问题?非常感谢。
i = 1;
int sum = 0;
while (i <= n - 1) {
sum = sqrt((vector1[i] - vector2[i])^2);
i++;
}
printf("%d", sum);
我的服务器中有下面的代码,当我运行它时,它将只从我的客户端读取输入一次,然后从try块中分离出来,并最终结束while(true)循环。
public void run() {
while (true) {
try {
inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
a = int(input())
b = int(input())
c = int(input())
result = 0
while a < b:
result = a * 2
print(result)
if result > c:
break
a += 3
我用了a=5b= 12,c= 16,解是101622,我不知道这16和22是从哪里来的?
我的程序基本上是获得用户的输入和比较词,是字谜的相互联系。我已经用Unix编译了这个程序,并针对它运行了val研-v,但是当所有堆分配都在退出时,我不知道内存泄漏是从哪里来的。这是我的主要方法和缬草产量。
int main()
{
// Create a head node for the linked list, and a newNode variable to
//add to the list
struct node *newNode;
struct node *head = malloc(sizeof(struct node));
我在玩C,并决定构建我自己的strlen()和did.But函数,因此我惊讶地发现{}能做什么。这是我的密码:
#include <stdio.h>
#include <assert.h>
int mystrlen(char *s)
{
int i = 0;
assert(s[0] !='\0');
for(i = 0; s[i] !='\0'; i++)
// Placing {} here causes the error to disappear //
return i;
}
int m
在我的bash脚本中,我希望读取文件的内容,并通过循环将文件的每一行附加到一个空字符串中。这似乎很容易做到,我认为我已经基于SO上的其他帖子(如Concatenate inputs in string while in loop)正确地实现了它,但最终结果似乎仍然是一个空字符串。很明显,我做错了什么,但我对bash脚本并不是很有经验,所以我可以使用一个快捷的方法。 我的bash脚本: #!/bin/bash
SOME_STRING=""
cat .env | while read line
do
SOME_STRING+="$line"
done
e
我正在尝试在Python中通过从基数39到基数10的来回转换来进行自定义基数转换。它工作得很好,除了我丢失了字符串的最后一个字母: #base 39(custom characters)
chars = 'esiarntolcdugpmhbyfvkwzxjq 0.,123456789'
nchars = len(chars)
#text that is converted (I am not bob btw)
text = 'hello everyone, bob here'
#convert to decimal
final = 0
for i, v
我正在编写这个简单的脚本,它被转换成一个守护进程并在后台运行。它需要监视一个进程类型,比如ls命令进程。
我的方法是,使用ps命令,有一个while循环来不断地检查进程类型。如果它检测到它,它将把它附加到一个文件中。
我想知道这是不是写这篇文章的坏方法?
我的代码如下
while true
do
if [[ $(ps -aux | grep -w "ls") ]]
then
#append to file
fi
done &
在C语言中,我会用循环来解决这个问题。为了表达这一想法,类似于:
void foo(int x){
while(x > 0){
printf("%d", x % 10);
x /= 10;
}
}
使用F#,我无法使函数返回单个值。我试过:
let reverse =
let aux =
fun x ->
x % 10
let rec aux2 =
fun x ->
if x = 0 then 0
#include <iostream>
#include <vector>
using namespace std;
int main () {
std::vector<int> winning_numbers {13579,26791,26792,33445,55555,62483,77777,79422,85647,93121};
std::cout <<"Please Enter Your Numbers: ";
int users_numbers;
std::cin >&g
我正在学习bash,但我无法理解这个示例代码:
while IFS= read -r line2;
do
if [[ "$line1" == "$line2" ]]
then
(( i++ ))
fi
done <<< "$lines"
特别是done <<< "$lines"行,<<<是什么意思?
我还找到了其他例子,例如:
while read line
do
echo
我有一个名为“NotesView”的选项: documentStatus = 0,
我有一个lotusscript代理,它从"status“视图获取所有文档,并将documentStatus值更改为1。
在代理运行之后,"status“视图应该是空的,但是有些文档是代理没有处理的。
我犯了个错误吗?
有一个Lotussript代码:
Set doc = view.Getfirstdocument()
While Not ( doc Is Nothing)
Set docNext = view.Getnextdocument(doc)
Call d
我想做一个非常简单的脚本:我只想在我的计算机上找到程序的最新版本,比如svn。我想将结果加载到一个变量中,比如mysvn
所以我写了这个脚本:
#!/bin/sh
mysvn="foobar"
best_ver=0
which -a svn | while read p
do
version=$("$p" --version | grep 'version ' | grep -oE '[0-9.]+' | head -1)
if [[ "$version" > "$best_ver&
我有一个测试计划如下:
Test Plan
SQL 1
Save to file A
Outer While loop
CSV= file A
SQL 2 => many rows
Save to file B
Inner While loop <--- executes only once
CSV = file B, recycle at EOF = false, stop thread at EOF = false
我不知道我的查询出了什么问题,但它没有跳出while循环。我想这就是我计算时间的方式,但不确定。
DECLARE @start DATETIME = GETDATE(), @currenttime INT = 0
while @currenttime <= 1 --- represent min
begin
[execute Query]
' this will always return 0 and keep executing query even though the 1 min has been reached
set @currenttim
如果我的txt文件包含与以下类似的行:
1.1, 0.1836856, 5.6
3.3, -5.5, 43.44
-0.38162, 6.636666E-08, 3.1
1.01516E-07, 0.3695395, 1.5
如何将文件读入元组?
var reader = new StreamReader(File.OpenRead(@"C:\MyFile.txt"));
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(','
我已经在一个线程的循环中WebService调用了代码。我使用不同的参数构建URL,并使用HttpURLConnection调用WS,如下所示:
public void run() {
//establish connection to db in another class
while(true) {
//Get args value from another class
for(String arg : args) {
try {
String invokeWS = "URL