Question

In: Computer Science

#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10;...

  1. #include <iostream>

  2. using namespace std;

  3. int main() {

  4. int even=0,odd=0,sum=0,sum2=0,largest,smallest;

  5. int num,i;

  6. for ( i=1; i<=10; i++){

  7. cout << " Enter " << i << " number: ";

  8. cin >> num;

  9. if ( num%2==0){

  10. even++;

  11. sum+=num;

  12. }

  13. else {

  14. odd++;

  15. sum2+=num;

  16. if(num>largest){

  17. largest = num;

  18. }

  19. if(num<largest) {

  20. smallest = num;

  21. }

  22. }

  23. cout << " The sum of even number is : " << sum << endl;

  24. cout << " The total-count of even number is : " << even << endl;

  25. cout << " The sum of odd number is : " << sum2 << endl;

  26. cout << " The total-count of odd number is : " << odd << endl;

  27. cout << " The largest number is : " << largest << endl;

  28. cout << " The smallest number is : " << smallest << endl;

  29. }

=====

CAN SOMEONE FIX MY CODE ?? BECAUSE THE SMALL INTEGER WONT SHOW THE CORRECT VALUE , PLEASE DONT USE ANY PREPROCESSOR DIRECTIVES ONLY <IOSTREAM> AND JUST FIX SOMEHTING TO MY CODE SO THE SMALLER INTEGER WILL SHOW THE CORRECT VALUE

=====

Solutions

Expert Solution

#include <iostream>

using namespace std;
int main() {
int c=0;
int even=0,odd=0,sum=0,sum2=0,largest,smallest;
int num,i;
for ( i=1; i<=10; i++){
cout << " Enter " << i << " number: ";
cin >> num;
if(c==0){
largest=num;
smallest=num;
c=c+1;
}

if(num%2==0){
even++;
sum+=num;
}
else
odd++;
sum2+=num;
if(num>largest){
largest = num;
}
if(num<largest) {
smallest = num;

}
}
cout << " The sum of even number is : " << sum << endl;
cout << " The total-count of even number is : " << even << endl;
cout << " The sum of odd number is : " << sum2 << endl;
cout << " The total-count of odd number is : " << odd << endl;
cout << " The largest number is : " << largest << endl;
cout << " The smallest number is : " << smallest << endl;
return 0;

}

#output


#if you have any doubts comment below...if you like give thumbs up..


Related Solutions

in C++, #include<iostream> using namespace std; const int NUM = 10; void prepareArr(int a[]); int countEven...
in C++, #include<iostream> using namespace std; const int NUM = 10; void prepareArr(int a[]); int countEven (int b[]); int main() { int arr[NUM]; // write a statement to call prepareArr to set values for the array // write a statement to call countEven and print the data returned for(int i = 0; i<NUM; i++) cout << arr[i] <<" "; cout <<endl; return 0; } void prepareArr(int a[]) { //randomly generate NUM integers in the range [0,99] and save them in...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1;...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1; hour <= 12; hour++)     {         for (min = 0; min <= 59; min++)         {             cout << hour << ":" << min << "AM" << endl;         }     }       return 0; } 1.      Type in the above program as time.cpp. Add a comment to include your name and date. Compile and run. 2.      What is the bug or logic error in the above program? Add the...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int SIZE = 20;     char str[SIZE];     char str1[SIZE];     int n;     int k =1;        printf("Enter a word: \n");     fgets(str,SIZE,stdin);     printf("Enter another word: \n");     fgets(str1,SIZE,stdin);        if (str1[strlen(str1) - 1] == '\n')     {         str1[strlen(str1)-1] = '\0';     }     if (str[strlen(str) - 1] == '\n')     {         str[strlen(str)-1] = '\0';     }      ...
Use while loop for the num inputs #include #include using namespace std; int main() {   ...
Use while loop for the num inputs #include #include using namespace std; int main() {    long long int digit;    long long int num1, num2, num3, num4, num5;    int ave;       cout << "Enter a 10 digit number: ";    cin >> digit;       num5 = digit %100;    digit = digit / 100;       num4 = digit %100;    digit = digit / 100;    num3 = digit %100;    digit = digit /...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool a = true; bool b= true;    //Print the Conjunction function cout<<"\n\nConjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(P∧Q)" <<endl; cout<< a <<"\t"<< b <<"\t"<< conjunction(a,b) <<endl; cout<< a <<"\t"<< !b <<"\t"<< conjunction(a,!b) <<endl; cout<< !a <<"\t"<< b <<"\t"<< conjunction(!a,b) <<endl; cout<< !a <<"\t"<< !b <<"\t"<< conjunction(!a,!b)<<endl;    //Print the Disjunction function cout<<"\n\nDisjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(PVQ)" <<endl; cout<< a <<"\t"<< b <<"\t"<< disjunction(a,b) <<endl;...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool a = true; bool b= true;    //Print the Conjunction function cout<<"\n\nConjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(P∧Q)" <<endl; cout<< a <<"\t"<< b <<"\t"<< conjunction(a,b) <<endl; cout<< a <<"\t"<< !b <<"\t"<< conjunction(a,!b) <<endl; cout<< !a <<"\t"<< b <<"\t"<< conjunction(!a,b) <<endl; cout<< !a <<"\t"<< !b <<"\t"<< conjunction(!a,!b)<<endl;    //Print the Disjunction function cout<<"\n\nDisjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(PVQ)" <<endl; cout<< a <<"\t"<< b <<"\t"<< disjunction(a,b) <<endl;...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count =...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count = 0, maximum = 0, minimum = 0;     cout << "Enter your student ID number: ";     cin >> studentid;     cout << "Student ID Number = " << studentid << endl;     while (studentid != 0)     {          numberreverse[count] = studentid % 10;          if (count == 0)          {              minimum = numberreverse[count];              maximum = minimum;          }          else...
#include<iostream> using namespace std; int main() {    int number_resistors;    double Resistors;    double series;...
#include<iostream> using namespace std; int main() {    int number_resistors;    double Resistors;    double series;    double parellel;    cout << "how many resistors: ";    cin >> number_resistors;    while (number_resistors != 0)    {        cout << "Enter the values of" << number_resistors << " resistors ";        for (int i = 0; i < number_resistors; i++) {            cin >> Resistors;            series += Resistors;                parellel...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat = 'y'; for (;repeat == 'y';){ char emplyeename[35]; float basic_Salary,EPF, Dearness_Allow, tax, Net_Salary , emplyee_id; cout << "Enter Basic Salary : "; cin >> basic_Salary; Dearness_Allow = 0.40 * basic_Salary; switch (01) {case 1: if (basic_Salary <= 2,20,00) EPF = 0; case 2: if (basic_Salary > 28000 && basic_Salary <= 60000) EPF = 0.08*basic_Salary; case 3: if (basic_Salary > 60000 && basic_Salary <= 200000)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT