本文介绍了将输入和打印置于循环中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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]);
}
推荐答案
#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]);
}
这篇关于将输入和打印置于循环中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!