Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MSIL
1. Write a program to input a set of five numbers and print them out in the reverse order of input. Put both the input and printing in loops.
Variables
numbers[]
counter
Output
Input five numbers:
1? 235
2? 256.23
3? 458
4? 265.12
5? 5
Here they are: 5 265.12 458 256.23 235


Here are my coding, can anyone check for me because i seen like got some error on it

XML
#include <stdio.h>
#include <conio.h>
#define arr_size 5
void main(void)
{
    float numbers[arr_size] ;
    int counter;
    clrscr();
    printf("Input five numbers: \n");
    for (counter = 0; counter < arr_size; ++counter)
        {
            pr1ntf("%i?",counter + 1);
            scanf("%f", &numbers[counter]); `
        }
    printf("Here they are:");
    for (counter = 4; counter >= 0; --counter)
    printf(" %g",numbers[counter]);
}
Posted

1 solution

firstly you have printf spelt with a 1 and that would not compile.

Also remove the ' after the scanf line in the first loop as this would also make it not compile.

Your algorithm is however sound.

Try using following code

C#
#include <stdio.h>
#define arr_size 5
void main(void)
{
    float numbers[arr_size] ;
    int counter;
    printf("Input five numbers: \n");
    for (counter = 0; counter < arr_size; ++counter)
        {
            printf("%i?",counter + 1);
            scanf("%f", &numbers[counter]);
        }
    printf("Here they are:");
    for (counter = 4; counter >= 0; --counter)
    printf(" %g",numbers[counter]);
}
 
Share this answer
 
v5
Comments
Jayfam 16-Apr-11 16:50pm    
i correct the error already, the the program still cannot run
Guyverthree 16-Apr-11 16:59pm    
i think the problem was conio.h not having clrscr() ni it.

I ahve changed it for antoher function that does the same thing from cstdlib
LloydA111 16-Apr-11 16:55pm    
Why can it still not run?
Jayfam 16-Apr-11 17:03pm    
it showing me the error fatal error: cstdlib: No such file or directory
Guyverthree 16-Apr-11 17:06pm    
can you just remove the lib and the system("cls"); functions and compile and run the code then ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900