[SOLVED]problems with an array

Hi! I have some problems with a program that I tryed to make this morning.It has to make an array of up to 25 elements, show the elements on screen, write the even numbers in a new array and show it on screen too.I know it's a simple program but I really can't figure out where my my mistake is...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream.h>
#include<stdlib.h>

const int N=25;

void main()
{
	int k; //number of elements in the massiv
	int p[N]; 
	int br=0; //number of even numbers
	int c[N]; //massiv of even numbers
	int m=0;

	cout<<"Vyvedete razmernost"<<endl;
	cin>>k;

	for(int i=0;i<k;i++) 
	{
		cout<<"Vyvedete el.No "<<i+1<<endl;
		cin>>p[i];
	}

     	for(i;i<k;i++)
	{
		cout<<"El No "<<i+1<<"e "<<p[i]<<endl;
	}


	for(i;i<k;i++)
	{
		if((p[i]%2)!=0)
		{ c[m]=p[i];
		   br++;
		   m++;
		};

	}


    
	cout<<"Nechetnite chisla sa: "<<endl;

	for(i;i<br;i++)
	{
		cout<<c[i]<<",";
	}

	exit(1);

}
Last edited on
a massiv
A what? You must mean an array.

If n%2!=0, then n is an odd number.
Your program looks very old standard,
the headers should be
1
2
3
#include<iostream>
#include<cstdlib>
// all the standard stuff is in the std namespace 

main should be an int
instead of exit(1); you should have return 0; i loses its scope after the 1st for and you should set it to 0 in each loop
Last edited on
thanks :)
Last edited on
Topic archived. No new replies allowed.