加上数组中的所有赔率数。 [英] sum all odds number in array.

查看:76
本文介绍了加上数组中的所有赔率数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个C代码,请求用户输入并将它们存储在数组中。输入数量由用户决定,并且限制为100输入。然后我需要将数组传递给递归函数求和数组中的所有奇数值。最后,将所有奇数的总和返回给用户。


但是,我收到的错误表明系统找不到指定的文件。

所以我不确定我的代码是否正确。

我使用的是Visual C ++ express 2005.


下面是我的代码:


#include< stdio.h>


int sumOdd(int x);

int main( )

{

int arr [100];

int readNum;

int sumAllOdd;

int i;


printf(你最多可以输入100个数字。\\ n请输入一个整数:);

scanf_s("%d"& readNum);


if(readNum> 100)

printf(" Error.It超过100个数字。\ n请输入一个整数:);


for(i = 0;我< readNum; i ++)

scanf_s("%d",& arr [i]);


sumAllOdd = sumOdd();

}


int sumOdd(int x)

{

int i;

int temp = 0;

int arr [100];

for(i = 0; i< 100; i ++)

{

if(arr [i]%2 == 0)

返回0;

其他

temp + = arr [我];

返回1;

}

}

解决方案

可以找不到指定的文件?这是在编译,链接或运行期间吗?


当我尝试执行程序时出现错误系统找不到指定的文件


< blockquote>然后你可能得到了可执行文件的名称或位置错误。


i am trying to write a C code which request input from user and store them in array.Number of inputs is determined by the user and it is limited to 100 inputs.Then I need to pass the array to recursive function to sum all odd values in the array.Finally,return the sum of all odd numbers to the user.

However, i got the error which stated that the system cannot find the file specified.
So I am not sure if my code is correct.
I am using Visual C++ express 2005.

Below is my code:

#include<stdio.h>

int sumOdd(int x);
int main ()
{
int arr[100];
int readNum;
int sumAllOdd;
int i;

printf("You may enter up to 100 numbers.\nPlease enter an integer:");
scanf_s("%d",&readNum);

if(readNum>100)
printf("Error.It exceeds 100 numbers.\nPlease enter an integer:");

for( i = 0; i < readNum; i++)
scanf_s("%d",&arr[i]);

sumAllOdd = sumOdd();
}

int sumOdd(int x)
{
int i;
int temp=0;
int arr[100];
for(i=0;i<100; i++)
{
if(arr[i]%2==0)
return 0;
else
temp += arr[i];
return 1;
}
}

解决方案

Can not find which specified file? Was this during compilation, linking or running?


when i try to execute the program i got the error "The system cannot find the file specified"


Then you have probably got the name or the location of the executable file wrong.


这篇关于加上数组中的所有赔率数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆