将输入和打印置于循环中 [英] Put both the input and printing in loops

查看:80
本文介绍了将输入和打印置于循环中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

#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]);
}

推荐答案

首先,您将printf拼写为1,并且无法编译.

另外,请在第一个循环的scanf行之后删除'',因为这也将使其无法编译.

您的算法是正确的.

尝试使用以下代码

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

#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]);
}


这篇关于将输入和打印置于循环中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆