Question

In: Computer Science

User is asked to enter a series of numbers. That input will stop when user enters...

User is asked to enter a series of numbers. That input will stop when user enters -9999. Find a maximum number from that series and a minimum number from that series. Output the location of Maximum number and minimum number. 

Write a C++ program that asks the user to repeatedly input positive numbers until   -1 is pressed. Your program should print the second largest number and the count of even and odd numbers. 

Write a C++ program that asks the user to enter a positive number N, and print the following pattern. The pattern is shown for N = 5.

12345

23451

34521

45321

54321

Write a program that takes a set of N integers and count the frequency of ODD digits appeared in these N integers.

Sample Input:

How Many Numbers you want to input: 3

Number 0: 7809

Number 1: 1127

Number 2: 8381

Output: 

    Frequency of appeared ODD digits: 7

 The digits 7809. 5127. 8381. So the count of these ODD digits is 7.

Solutions

Expert Solution

1)

#include<iostream>
using namespace std;

int main()
{
    int x,min=999999,max=-99999;
    int minpos=0,maxpos=0,count=0;
    cin>>x;
    while(x!=-9999)
    {
        count++;
        if(x > max)
        {
            max = x;
            maxpos = count;
        }
        if( x < min)
        {
            min = x;
            minpos = count;
        }
        cin>>x;
    }
  
    cout<<"Maximum number is : "<<max<<" And its location is : "<<maxpos<<endl;
    cout<<"Minimum number is : "<<min<<" And its location is : "<<minpos<<endl;
  
    return 0;
}

Input:

15
13
33
99
55
-9999

Output :

Maximum number is : 99 And its location is : 4
Minimum number is : 13 And its location is : 2


2)

#include<iostream>
using namespace std;

int main()
{
   int x,max2=-999999,max=-999999;
   int numodd=0,numeven=0;
   cin>>x;
   while(x!=-1)
   {
       if(x%2 == 0)
           numeven++;
       else
           numodd++;

       if(x > max)
       {
           max = x;
       }
       if( x < max && x > max2)
       {
           max2 = x;
       }
       cin>>x;
   }
  
   cout<<"Second largest number is : "<<max2<<endl;
   cout<<"Count of odd numbers is : "<<numodd<<" And count of even numbers is : "<<numeven<<endl;
  
   return 0;
}

Input :

15
13
33
99
55
-1

Output :
Second largest number is : 55
Count of odd numbers is : 5 And count of even numbers is : 0


3)

#include<iostream>
using namespace std;

int main()
{
   int N,i,j,x;
   cout<<"Enter a positive number (N) : ";
   cin>>N;
  
   for(x=1;x<=N;x++)
   {
       for(i=x;i<=N;i++)
       {
           cout<<i;
       }
       j=x-1;
       while(j>0)
       {
           cout<<j;
           j--;
       }
       cout<<endl;
   }
  
   return 0;
}

Input:

Enter a positive number (N) : 7

Output:

1234567
2345671
3456721
4567321
5674321
6754321
7654321

4)

#include<iostream>
using namespace std;

int main()
{
   int N,i,num[50],odddigits=0;
   cout<<"How many numbers you want to input : ";
   cin>>N;
  
   for(i=0;i<N;i++)
   {
       cout<<"Number"<<i<<": ";
       cin>>num[i];
      
   }
  
   for(int i=0;i<N;i++)
   {
       int x=num[i];
       while(x)
       {
           if((x%10)%2 != 0)
               odddigits++;
           x /= 10;
       }
   }
   cout<<"Frequency of appeared ODD digits : "<<odddigits<<endl;
  
  
   return 0;
}

Input :
How many numbers you want to input : 3
Number 0: 7809
Number 1: 1127
Number 2: 8381

Output:

Frequency of appeared ODD digits : 7


Related Solutions

Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
In C# When the user enters an invalid value, ask the user to repeatedly enter the...
In C# When the user enters an invalid value, ask the user to repeatedly enter the value until a valid value has been entered. Gender must be ‘M’ or ‘F’. Residency must be ‘I’ or ‘O’. Existing Code: using System; public class Student {   public int credit;   public String firstname, lastname, gender, residency, edate;   public void input()   {     Console.WriteLine("\nWelcome to the Continental University Registration System!"); Console.WriteLine("\nEnter data about a student"); Console.Write("First Name: "); firstname = Console.ReadLine(); Console.Write("Last Name: "); lastname...
Design a complete program that asks the user to enter a series of 20 numbers. The...
Design a complete program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display each of the following data: I. The lowest number in the array II. The highest number in the array III. The total of the numbers in the array IV. The average of the numbers in the array *PYTHON NOT PSUEDOCODE AND FLOW CHART!!!!*
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
Design JavaFX application with 7 labels and one textfield where user enters input inches.  When user enters...
Design JavaFX application with 7 labels and one textfield where user enters input inches.  When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches.   Use class P5 that extends Application  with start method in it, and class P5Pane that extend GridPane. The only inctance variables for P5Pane class are inputInches where user enters input  inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion.  Use the following names for instance variables:...
Assume user will enter letters or numbers that are out of range. When user inputs invalid...
Assume user will enter letters or numbers that are out of range. When user inputs invalid values, show an alert message and ask user to enter a valid value again. Validate first and then proceed with the program. isNaN() method may be useful. Must validate user input. 1. Suggested Filename: fortune.html & fortune.js Write a program that simulates a fortune cookie. The program should display one of five unique fortunes, depending on user input. The user must enter a number...
Create a form in which the user enters two separate numbers (x and y), and when...
Create a form in which the user enters two separate numbers (x and y), and when the user clicks the appropriate button, math functions are performed on these two numbers and output back on to the form. INPUT User can enter two separate numbers (one for the x variable, and one for the y variable) User can input their information: The user must be able to enter information about themselves, including first name, last name, address, phone PROCESSING The user...
I need to ask a user what numbers they want to enter. They can enter as...
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't...
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT