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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// Accept n number of inputs from the keyboard and display
//the odd numbers in ascending order , even numbers in descending order
#include<iostream>
using namespace std;
int main()
{
int ecount, ocount, limit, no, i,j,t,e,o, odd[100], even[100], second;
ecount=0;
ocount=0;
no=0;
cout<<"Enter limit of numbers.\n";
cin>>limit;
for(i=1;i<=limit;i++)
{
cout<<"enter "<<i<<"st no ";
cin>>no;
//Summing odd and even numbers
//Sum Even numbers
if(no%2==0)
{
even[ecount++]=no;
}
//Sum Even numbers
else
{
odd[ocount++]=no;
}
}
cout<<"The frequency of even numbers is "<<ecount<<" \n";
cout<<"The event of odd numbers is "<<ocount<<" \n";
e=ecount;
o=ocount;
//C1.2 III
// Accept n number of inputs from the keyboard
// Display the sum of all the given numbers.
// Display the numbers in ascending order.
//Sorting in Ascending Order (low first, then up)
/*
for(i=1; i<=limit; i++)
{
for(j=i+1; j<=limit; j++)
{
if(odd[i] > odd[j])
{
t = odd[i];
odd[i] = odd[j];
odd[j] = t;
}
}
}*/
for(ocount=o; ocount>=0; ocount--)
{
for(second=ocount-1; second>=0; second--)
{
if(odd[ocount] > odd[second])
{
t = odd[ocount];
odd[ocount] = odd[second];
odd[second] = t;
}
}
}
//Sorting in Descending Order (high first, then down)
for(ecount=e; ecount>=0; ecount--)
{
for(second=ecount-1; second>=0; second--)
{
if(even[ecount]<even[second])
{
t = even[ecount];
even[ecount] = even[second];
even[second] = t;
}
}
}
//Display in Descending Order (high first, then down)
cout<<"Even numbers (Descending): ";
for(ecount=e; ecount>0; ecount--)
{
cout<<even[ecount]<<" ";
}
cout<<"\n";
//Display in Ascending Order
cout<<"Odd numbers (Ascending): ";
for(ocount=o; ocount>0; ocount--)
{
cout<<odd[ocount]<<" ";
}
return 0;
}
|