i have here a code that can distinguish between odd and even numbers but my problem is how can i add for even numbers and odd numbers. here is my code...
//odd and even functions
#include <iostream.h>
void even (int a,int b,int c, int d,int e);
void odd (int a,int b, int c,int d,int e);
void addeven (int a,int b,int c,int d, int e);
void addodd (int a, int b,int c, int d,int e);
void even (int a,int b,int c,int d,int e)
{
if ((a%2)==0) cout << a << " it is even.\n";
if ((b%2)==0) cout << b << " it is even.\n";
if ((c%2)==0) cout << c << " it is even.\n";
if ((d%2)==0) cout << d << " it is even.\n";
if ((e%2)==0) cout << e << " it is even.\n";
}
void odd (int a,int b, int c,int d,int e)
{
if ((a%2)!=0) cout << a << " it is odd.\n";
if ((b%2)!=0) cout << b << " it is odd.\n";
if ((c%2)!=0) cout << c << " it is odd.\n";
if ((d%2)!=0) cout << d << " it is odd.\n";
if ((e%2)!=0) cout << e << " it is odd.\n";
}
void addeven (int a,int b,int c,int d, int e)
{
cout << "Addition for Even Numbers!" << endl;
cout << "Result: " << endl;
}
void addodd (int a, int b,int c, int d,int e)
{
cout << "Addition for Odd Numbers!" << endl;
cout << "Result: " << endl;
}
main ()
{
int a, b, c, d, e;
cout << "Enter five numbers: ";
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
even (a,b,c,d,e);
odd (a,b,c,d,e);
addeven (a,b,c,d,e);
addodd (a,b,c,d,e);
}
//odd and even functions
#include <iostream.h>
void even (int a,int b,int c, int d,int e);
void odd (int a,int b, int c,int d,int e);
void addeven (int a,int b,int c,int d, int e);
void addodd (int a, int b,int c, int d,int e);
void even (int a,int b,int c,int d,int e)
{
if ((a%2)==0) cout << a << " it is even.\n";
if ((b%2)==0) cout << b << " it is even.\n";
if ((c%2)==0) cout << c << " it is even.\n";
if ((d%2)==0) cout << d << " it is even.\n";
if ((e%2)==0) cout << e << " it is even.\n";
}
void odd (int a,int b, int c,int d,int e)
{
if ((a%2)!=0) cout << a << " it is odd.\n";
if ((b%2)!=0) cout << b << " it is odd.\n";
if ((c%2)!=0) cout << c << " it is odd.\n";
if ((d%2)!=0) cout << d << " it is odd.\n";
if ((e%2)!=0) cout << e << " it is odd.\n";
}
void addeven (int a,int b,int c,int d, int e)
{
cout << "Addition for Even Numbers!" << endl;
cout << "Result: " << endl;
}
void addodd (int a, int b,int c, int d,int e)
{
cout << "Addition for Odd Numbers!" << endl;
cout << "Result: " << endl;
}
main ()
{
int a, b, c, d, e;
cout << "Enter five numbers: ";
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
even (a,b,c,d,e);
odd (a,b,c,d,e);
addeven (a,b,c,d,e);
addodd (a,b,c,d,e);
}
Comment