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,r eturn 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.\nPleas e enter an integer:");
scanf_s("%d",&r eadNum);
if(readNum>100)
printf("Error.I t exceeds 100 numbers.\nPleas e enter an integer:");
for( i = 0; i < readNum; i++)
scanf_s("%d",&a rr[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;
}
}
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.\nPleas e enter an integer:");
scanf_s("%d",&r eadNum);
if(readNum>100)
printf("Error.I t exceeds 100 numbers.\nPleas e enter an integer:");
for( i = 0; i < readNum; i++)
scanf_s("%d",&a rr[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;
}
}
Comment