Results 1 to 3 of 3

Thread: Need lowest/highest number

  1. #1
    Join Date
    Jan 2009
    Posts
    318

    Need lowest/highest number

    hi,
    i have been messing around with this for the past hour and don't know whats wrong and so I would appreciate if someone can point out my problem. What im trying to do is search through a user input (not above 10) find the highest number and lowest no in c++.Thanks in advance for your help!!!
    # include <iostream.h>
    #include <conio.h>
    void main ()

    {
    int lowest = 0;
    int number = 0;

    cout<<"Enter in the number"<<endl;
    cin>>number;
    lowest = number;
    for(int count =0; count < 3; count++)
    {
    cout<<"Enter in the number"<<endl;
    cin>>number;
    if(number < lowest)
    lowest = number;
    }

    cout<<lowest;

    }

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Need lowest/highest number

    HTML Code:
    # include <iostream.h>
    #include <conio.h>
    void main ()
    
    {
    int lowest = 0;
    int number = 0;
    
    cout<<"Enter in the number"<<endl;
    cin>>number;
    lowest = number;
    for(int count =0; count < 3; count++)
    {
    cout<<"Enter in the number"<<endl;
    cin>>number;
    if(number < lowest)
    lowest = number;
    }
    
    cout<<lowest;
    
    }
    if you want to pront the largest or smallest no In C++, you can declare lowest when you need it.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Need lowest/highest number

    Program to smallest or largest no in C++
    #include<iostream.h>
    #include<stdio.h>
    #include<stdlib.h>
    void main()
    {
    int arr[20],n,l,b,c,i;
    cout<<"enter the no : ";
    cin>>n;
    for(i=0;i<n;i++)
    {
    cout<<"Element "<<i+1<<" : ";
    cin>>arr[i];
    }
    for(i=0;i<n;i++)
    {
    c=1;
    for(int j=0;j<n;j++)
    {
    if(arr[i]>arr[j])
    c+=1;
    }
    if(c==n) /*instead of= its ==*/
    {
    break;
    }
    }
    l=arr[i];
    for(i=0;i<n;i++)
    {
    c=1;
    for(int k=0;k<n;k++)
    {
    if(arr[i]<arr[k])
    c+=1;
    }
    if(c==n) /*instead of= its ==*/
    {
    break;
    }
    }
    b=arr[i];
    cout<<"Largest no. is "<<l<<"\nSmallest no. is "<<b;
    system("PAUSE");
    }

Similar Threads

  1. Replies: 10
    Last Post: 24-11-2011, 12:08 PM
  2. Looking for Highest CFM with lowest db's?
    By Ajooba AB in forum Hardware Peripherals
    Replies: 5
    Last Post: 03-05-2011, 10:29 PM
  3. Lowest latency on online game with SG TCP Optimizer
    By Baby bon bon in forum Video Games
    Replies: 5
    Last Post: 30-03-2011, 05:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,605,752.74477 seconds with 17 queries