Homework Help 
Author Message
 Homework Help

hi- i just started learning C and I have this hw question. We are supposed to
write a program that finds the smallest of several integers. Assue that the
first value read specifies the number of values remaining. Here's the code I
have so far (we wrote the pseudocode in class) so now I'm working on the code.

#include <stdio.h>
main ()
{      
int num1, num2, amt;
        printf(" Please enter the number of integers (greater than -1): ");
        scanf(" "  ,amt);
        printf(" Please enter the first number: ");
        scanf("%d" , num1) ;
        for (    , amt>0, amt--)
        {
                printf(" Please enter the second number: ");
                scanf("%d" , num2) ;
        if      (num1 < num2)
                num1=num1;
        else
                num1=num2;
        }

Quote:
}

The missing parts are the parts I'm confused about what to put there. Can you
please tell me if I'm on the right track.
Thanks!
Lisa


Sun, 29 Jul 2001 03:00:00 GMT  
 Homework Help

Quote:

>hi- i just started learning C and I have this hw question. We are supposed
to
>write a program that finds the smallest of several integers. Assue that the
>first value read specifies the number of values remaining. Here's the code
I
>have so far (we wrote the pseudocode in class) so now I'm working on the
code.

>#include <stdio.h>
>main ()
>{      
>int num1, num2, amt;
>        printf(" Please enter the number of integers (greater than -1): ");
>        scanf(" "  ,amt);
>        printf(" Please enter the first number: ");
>        scanf("%d" , num1) ;
>        for (    , amt>0, amt--)
>        {
>                printf(" Please enter the second number: ");
>                scanf("%d" , num2) ;
>        if      (num1 < num2)
>                num1=num1;
>        else
>                num1=num2;
>        }
>}
>The missing parts are the parts I'm confused about what to put there. Can
you
>please tell me if I'm on the right track.
>Thanks!
>Lisa

Here is one thing I would suggest. Write your code incremental. After each
step make sure your program compiles and executes correctly.
Start with the smallest C program.

int main(void)
{
        return 0;

Quote:
}

Next write a program that reads in one number and then writes it out again.

#include <stdio.h>

int main(void)
{
        int             number;

        printf("Enter a non-negative number.\n");
        scanf("%d", &number);     /* Notice the & */
        printf("The number was %d.\n", number);

        return 0;

Quote:
}

Now lets do a program reading 10 numbers and printing them out.

#include <stdio.h>

int main(void)
{
        int             number;
        int             i;

        for (i = 0; i < 10; i++)
        {
                printf("Enter the next number.\n");
                scanf("%d", &number);
                printf("The number was %d.\n", number);
        }

        return 0;

Quote:
}

Now combine the last two programs to read a number that you use as the limit
for your for-loop.

Take it form here.

Carsten Hansen



Mon, 30 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. HOMEWORK HELP!

2. homework help(arrays + pointers)

3. a little homework help....

4. Payroll Processing Homework Help

5. Homework Help --- Ordering Three Inputted Numbers

6. HOMEWORK HELP, AGAIN!!

7. I will pay for homework help !HELLLPPPP !!!HELLLPPPP !!!

8. homework help scanning info from disk?

9. HOMEWORK HELP!!

10. Homework help: Where do I start?

11. C homework help - Reward offered

12. HOMEWORK HELP

 

 
Powered by phpBB® Forum Software