C程序数组和for循环练习
我必须编写一个函数来检查一个值是否位于使用for循环的N个元素的数组中C程序数组和for循环练习,c,arrays,C,Arrays,我必须编写一个函数来检查一个值是否位于使用for循环的N个元素的数组中 #include <stdio.h> int main () int N[100],n,i; printf ("Write the value of n:"); scanf ("%d",&n); i=0; printf ("Write the value of the element :"); scanf ("%d",&v[i]); for (i=0,i&
#include <stdio.h>
int main ()
int N[100],n,i;
printf ("Write the value of n:");
scanf ("%d",&n);
i=0;
printf ("Write the value of the element :");
scanf ("%d",&v[i]);
for (i=0,i<n,i++)
{
if (N[i]==n)
}
printf ("The value is located in the array :");
return 0;
#包括
int main()
int N[100],N,i;
printf(“写入n的值:”);
scanf(“%d”和“&n”);
i=0;
printf(“写入元素的值:”);
scanf(“%d”、&v[i]);
对于(i=0,i基本语法问题。请尝试:
#include <stdio.h>
int main(void)
{
int N[100],n,i;
printf ("Write the value of n:");
scanf ("%d",&n);
i=0;
printf("Write the value of the element :");
scanf("%d", &v[i]); /* v doesn't exist */
/* you are looping up to n, which could be anything */
for (i=0; i<n; i++)
{
/* you never populate N, so why would you expect n to be found?
the value of any element in N is indeterminate at this point */
if (N[i]==n)
{
printf ("The value is located in the array :");
}
}
return 0;
}
#包括
内部主(空)
{
int N[100],N,i;
printf(“写入n的值:”);
scanf(“%d”和“&n”);
i=0;
printf(“写入元素的值:”);
scanf(“%d”,&v[i]);/*v不存在*/
/*你正在循环到n,它可能是任何东西*/
对于(i=0;i您需要将printf
用括号括起来{printf();}
。您还必须关闭for
循环的括号。main
的括号在哪里?在printf
周围放上括号并不能解决这个问题。首先,您的整个main
函数需要括号;语法类似于int main(){…这里有代码…}
。你需要花一些时间阅读一本关于C语法的基本书籍。格式化代码被高估了“你需要用括号{printf();}括住printf”——请不要写无知的废话。