delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/02/10/07:10:48

From: "Rafal Maj" <maj_rafal AT poczta DOT onet DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: Odp: I think this is a for problem...
Date: Sat, 10 Feb 2001 10:48:50 +0100
Organization: Academic Computer Center CYFRONET AGH
Lines: 48
Message-ID: <9632r1$n4u$1@info.cyf-kr.edu.pl>
References: <pSVg6.203456$ge4 DOT 69048244 AT news2 DOT rdc2 DOT tx DOT home DOT com>
NNTP-Posting-Host: d-94-53-15.cyfronet.krakow.pl
Mime-Version: 1.0
X-Trace: info.cyf-kr.edu.pl 981798561 23710 149.156.1.175 (10 Feb 2001 09:49:21 GMT)
X-Complaints-To: news AT cyf-kr DOT edu DOT pl
NNTP-Posting-Date: 10 Feb 2001 09:49:21 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

#include <iostream.h>

main() {
  int count;
  cout << "How meany integers ?"<<endl;
  cin >> count;
  int smallest=0;
  for (int n=0; n<count; n++) {
    cout << "type integer no. " << n << ":" << endl;
    int i;
    cin >> i;
    if (n==0) smallest = i;
    if (i<smallest) smallest=i;
  }
  if (count>0)
    cout << "Smallest integer was : "<<smallest<<endl;
}

If You are using library conio.h instead of iostream.h , then repleace
instructions like :
  cout << ...    to   printf ( ... )
and
  cin >> ...  to scanf( ... )

Remember to press alt+f5 after program finised to see user screen.

Rafał


Użytkownik Bob & Chris Parrish <Rcprrsh AT cs DOT com> w wiadomo¶ci do grup
dyskusyjnych napisał:pSVg6.203456$ge4 DOT 69048244 AT news2 DOT rdc2 DOT tx DOT home DOT com...
> I need help with homework for beginning C.  The question is:
>
> "Write a program that finds the smallest of several integers.  Assume that
> the first value read specifies the number of values remaining".
>
> I think I use the for structure.  The chapter also covers the while, and
> switch structures.
>
> I don't know where to start.  Can anyone help?
> --
> Chris Parrish
> rcprrsh AT home DOT com
> 303/617-4126
>
>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019