leetcode第一问题称为twi_sum im遇到错误,请帮助我解决我所做的事情
这是我的leetcode第一天第一日问题,称为twe_sum am遇到错误,请帮助我解决我所做的错误, 在VS代码中,下面的代码没有出现错误,也没有输出,但是在Leetcode I中遇到了一个错误:
第25行:CHAR 5:错误:'MAIN'[SOLELE.C]的相互冲突类型 int main(int argc,char *argv []){ ^~~~ 如果我的代码只有22行,但是我在第25行
#include <stdio.h>
void main()
{
int n, a[10], i, j, t;
printf("enter the array size");
scanf("%d", &n);
printf("enter th array values");
for (i = 0; i < n; i++)
scanf("%d", &a[I]);
printf("enter the targest sum");
scanf("%d", &t);
for (i = 0; i < n; n++)
{
for (j = i+1; j < n; n++)
{
if (a[i] + a[j] == t)
{
printf("[%d,%d]", i, j);
}
}
}
}
第二次尝试中遇到了错误:我在最后一个IF语句中替换了一个新代码,以其他方式检查。所以,现在我得到了输出,但不是正确的
this is my leetcode 1st day 1st problem called two_sum am getting an error, please help me with the mistake what I have done,
in vs code this, below code was getting no error and also no output, but in leetcode I getting an error :
Line 25: Char 5: error: conflicting types for ‘main’ [solution.c]
int main(int argc, char *argv[]) {
^~~~
where my code is only 22 lines but I was getting error in the 25th line
#include <stdio.h>
void main()
{
int n, a[10], i, j, t;
printf("enter the array size");
scanf("%d", &n);
printf("enter th array values");
for (i = 0; i < n; i++)
scanf("%d", &a[I]);
printf("enter the targest sum");
scanf("%d", &t);
for (i = 0; i < n; n++)
{
for (j = i+1; j < n; n++)
{
if (a[i] + a[j] == t)
{
printf("[%d,%d]", i, j);
}
}
}
}
2nd try: I replaced with a new code in the last if statement to check in another way. so, now I got output but, not the correct one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据C标准,应像无参数的函数主
函数一样,而不是固定数量的元素,
您可以使用可变长度数组,例如
另一种方法是动态分配数组,就像
您可以编写每对一对一对 类的新线路中的
所有成对之
在
值
According to the C Standard the function main without parameters shall be declared like
Instead of the array with the fixed number of elements
you could use a variable length array like for example
Another approach is to allocated the array dynamically like
You can write either each pair of values in a new line like
Or after all pairs you could print the new line character like
{ay attention to that you have a typo
you need to write
尝试声明
main
为int main(int argc,char * argv [])
或int main(void)
。void main
通常不是有效的类型声明,因此我认为vs code and Leetcode不会将您的主声明视为程序的条目。Try declaring
main
asint main(int argc, char * argv[])
orint main(void)
.void main
is usually not a valid type declaration so I presume both VS Code and Leetcode do not treat your main declaration as the entry to your program.在LeetCode中,您无需(也不应该)编写自己的主要功能。 LeetCode具有自己的主要功能。另外,您不需要包含库。您需要做的就是仅实现
二Xosum
函数。这是两个总和问题的LeetCode的默认代码定义:
您需要做的是在
twosum()
函数中写代码。In leetcode, you don't need to (and should not) write your own main function. Leetcode has its own main function. Also you don't need to include libraries. What you need to do is just to implement the
twoSum
function.Here's Leetcode's default code definition for the two sum problem:
What you need to do is write code within the
twoSum()
function.