15,740,865 members
See more:
Hi, I would like to display the odd and even integers from 1 upto given number and display the sum of odd and sum of even but there's always an error saying too few parameters. (void function is required) And lastly where should i put the formula for getting the sum of odd and sum of even?

C++
```# include <stdio.h>
# include <conio.h>

void even_odd(int n);

int main()
{
int n, i ;
clrscr() ;
even_odd();
getch() ;
return 0;
}

void even_odd(int n){
printf("Enter Integer : ") ;
scanf("%d", &n) ;
printf("\nThe odd numbers are :\n\n") ;
for(i = 1 ; i <= n ; i = i + 2)
printf("%d\t", i) ;
printf("\n\nThe even numbers are :\n\n") ;
for(i = 2 ; i <= n ; i = i + 2)
printf("%d\t", i) ;
}
</conio.h></stdio.h>```
Posted
Updated 9-Jan-23 7:42am
v2

## Solution 1

Your problem is that `n` is not a parameter but a local variable
C++
`void even_odd(int n){`

must be replaced by
C++
```void even_odd()
int n;{```

Ooops, you also need to change the line before `main` to
C++
`void even_odd();`

If you compile as is, Turbo C will tell you that there is another problem because `i` and `n` are used in `even_odd` but declared in `main`.
the source code with both corrections will look like
C++
```# include <stdio.h>
# include <conio.h>

void even_odd();

int main()
{
clrscr() ;
even_odd();
getch() ;
return 0;
}

void even_odd(){
int n, i ;
printf("Enter Integer : ") ;
scanf("%d", &n) ;
printf("\nThe odd numbers are :\n\n") ;
for(i = 1 ; i <= n ; i = i + 2)
printf("%d\t", i) ;
printf("\n\nThe even numbers are :\n\n") ;
for(i = 2 ; i <= n ; i = i + 2)
printf("%d\t", i) ;
}
</conio.h></stdio.h>```

v3
Wendelius 30-Sep-15 11:06am
Looks good, 5.
Patrice T 30-Sep-15 11:23am
Thank you

## Solution 2

Quote:
an error saying too few parameters. (void function is required)

C
`void even_odd(int n) `

expects a parameter, but you call it without any:

`even_odd();`

Try it like this:

```# include <stdio.h>
# include <conio.h>

void even_odd();

int main()
{
int i ;
clrscr();
even_odd();
getch() ;
return 0;
}

void even_odd()
{
int i, n;
printf("Enter Integer : ") ;
scanf("%d", &n) ;

printf("\nThe odd numbers are :\n\n") ;
for(i = 1 ; i <= n ; i = i + 2)
printf("%d\t", i) ;

printf("\n\nThe even numbers are :\n\n") ;
for(i = 2 ; i <= n ; i = i + 2)
printf("%d\t", i) ;
}```

v4
Wendelius 30-Sep-15 11:07am
That should work just fine, a 5.
Leo Chapiro 30-Sep-15 11:33am
Thank you, Mika! :)

## Solution 3

Others have already described the problem with the call. So what comes to calculating the sum; You already have two loops, one for odd and another for even numbers, why not calculate the sum inside those loops.

Something like:
C++
```...
for(i = 1 ; i <= n ; i = i + 2) {
printf("%d\t", i) ;
odd_sum = odd_sum + i;
}
...```

[no name] 30-Sep-15 10:51am
thank you guys
Leo Chapiro 30-Sep-15 10:54am
A good one, +5!