Sample Run 1:
Enter 10 integers: 1 2 3 4 5 6 7 8 9 10
2 4 6 8 10
1 3 5 7 9
Sample Run 2:
Enter 10 grades: 78 79 80 81 82 83 67 66 65 90
The highest is 90.
The average is 77.10!
Sample Run 3:
Enter 10 integers: 1 2 3 4 5 6 7 8 9 10
Sum of even: 30
Sum of odd: 25
C++ code and sample runs
Sample run 1 source code
#include <iostream>
using namespace std;
int main()
{
int arr[10];
cout<<"\nEnter 10 integers: ";
for(int i=0;i<10;i++){
cin>>arr[i];
}
//print even numbers
for(int i=0;i<10;i++){
if(arr[i]%2==0)
cout<<arr[i]<<" ";
}
cout<<endl;
//print odd numbers
for(int i=0;i<10;i++){
if(arr[i]%2!=0)
cout<<arr[i]<<" ";
}
return 0;
}
Sample run 2 source code
#include <iostream>
using namespace std;
int main()
{
int grades[10];
cout<<"\nEnter 10 grades: ";
for(int i=0;i<10;i++){
cin>>grades[i];
}
int highest=grades[0];
int sum=0;
for(int i=0;i<10;i++){
if(grades[i]>highest)
highest=grades[i];
sum+=grades[i];
}
cout<<"\nThe highest is "<<highest<<".";
cout<<"\nThe average is "<<(sum/10.0)<<"!";
return 0;
}
Sample run 3 source code
#include <iostream>
using namespace std;
int main()
{
int arr[10];
cout<<"\nEnter 10 integers: ";
int sumEven=0;
int sumOdd=0;
for(int i=0;i<10;i++){
cin>>arr[i];
}
for(int i=0;i<10;i++){
if(arr[i]%2==0)
sumEven+=arr[i];
else
sumOdd+=arr[i];
}
cout<<"\nSum of even: "<<sumEven;
cout<<"\nSum of odd: "<<sumOdd;
return 0;
}
Comments
Leave a comment