# Understanding the Steps to Store Elements in Reversely Stored

Asked 2 months ago, Updated 2 months ago, 2 views

I created it as follows, but the terminal stopped with the following conditions:

``````/*
ex1402.c
*/

# include <stdio.h>

void reverseIntArray(inta[], int size)
{
inti,t;
for(i=0;i<size/2;i=i+1){
/* Replace a[i] and a[size-1-i]*/
t = a[i];
a[i] = a[size-1-i];
a[size-1-i] = t;
}
}

void readIntArray(inta[], int size)
{
inti;
for(i=0;i<size;i=i+1){
printf("%dth?", i=i+1);
scanf("%d", & a[i]);
}
}

void printIntArray(inta[], int size)
{
inti;
for(i=0;i<size;i=i+1){
printf("%d", a[i]);
}
printf("\n");
}

int main (void)
{
int data [100], size;

printf("n=? ");
scanf("%d", & size);

readIntArray(data,size);
printIntArray(data,size);
reverseIntArray(data,size);
printIntArray(data,size);

return 0;
}
``````

terminals:

``````\$ccex1402.c
\$ ./a.out
n = ?10
Number one? 1
``````

There was no error on the terminal, so I didn't even know where it was wrong.
What should I do?

By the way, it seems that the execution example should be like this.

``````\$./a.out
n = ?10
Number 0? 1
1st? 2nd.
2nd? 3rd.
Third? Four.
4th? 5th?
Number five? Number six.
6th? 7th.
Seventh? Eight.
8th? 9th.
Number nine? Number ten.
1　2　3　4　5　6　7　8　9　10
10  9　8　7　6　5　4　3　2　1
``````

c

2022-09-30 14:20

## 2 Answers

``````scanf("%d", & a[i]);
``````

The cause is the `scanf()` format string, and if you set `"%d"` to `"%d"`, you will be able to proceed.

If you specify `"%d"`, you may want to leave a space after the number, but one of the many traps in `scanf()` does not finish typing spaces in the format string until you enter non-blank characters after spaces like `1a` will not consume the last

``` 2022-09-30 14:20 ```
``` ```
``` for(i=0; i printf("%dth?", i=i+1); When the last semicolon is present, this for statement loops only this. If you want to repeat scanf("%d", & a[i]);, delete the semicolon at the end of the for statement. If possible, surround it with {}.for(i=0; i printf("%dth?", i=i+1){ scanf("%d", & a[i]); } Like this. 2022-09-30 14:20 If you have any answers or tips ```
``` Popular Tags python x 4436 android x 1590 java x 1475 javascript x 1385 c x 903 c++ x 831 ruby-on-rails x 681 php x 678 python3 x 651 html x 631 Popular Questions 359 No exact matches in call to instance method 'append' 350 (python) Abs function re-create question 345 Unable to install versioned in Google Colab 359 I'd like to set the upper limit for display of the Rails each statement. 347 Unable to run bash on Docker ```
``` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-109404861-1'); //아이콘 설정 feather.replace({color: '#ffc107', width: 12, height: 12}); //oembed document.querySelectorAll('oembed[url]').forEach(element => { const anchor = document.createElement('a'); anchor.setAttribute('href', element.getAttribute('url')); anchor.className = 'embedly-card'; element.appendChild(anchor); }); \$(document).ready(function () { // 스크랩 \$('#q_scrap').click(function () { \$.post("/scrap", {'qid': "11115"}, function (data) { }); \$('#q_scrap').popover('show'); setTimeout(function () { \$('#q_scrap').popover('hide'); }, 1000); }); //질문 추천 \$('#q_score').click(function () { if (\$(this).attr("data-on") == "off") { \$.post("/score_q", {'qid': "11115"}, function (data) { if (data == "OK") { var score = parseInt(\$('#q_score_num').text()) + 1; \$('#q_score_num').html(score); \$(this).attr("data-on", "on"); } }); } }); //신고 \$('#q_spam').click(function () { \$.post("/spam", {'qid' : "11115"}, function (data) { }); \$('#q_spam').popover('show'); setTimeout(function () { \$('#q_spam').popover('hide'); }, 1000); }); //수정 \$('#q_edit').click(function () { \$(location).attr('href', "/question/edit/11115"); }); //삭제 \$('#q_del').click(function () { \$(location).attr('href', "/question/delete/11115"); }); // 답글 추가 \$('#a_add').click(function () { \$(location).attr('href', "/answer/add/11115"); }); // 답글 수정 \$('.a_edit').click(function () { var aid = \$(this).attr("data-aid"); \$(location).attr('href', "/answer/edit/" + aid); }); //답글 삭제 \$('.a_del').click(function () { if (!confirm('Do you want to delete this answer?')) { return false; } var aid = \$(this).attr("data-aid"); \$(location).attr('href', "/answer/delete/" + aid); }); //답글 추천 \$('.a_score').click(function () { if (\$(this).attr("data-on") == "off") { \$(this).attr("data-on", "on"); var aid = \$(this).attr('data-aid'); \$.post("/score_a", {'aid': aid}, function (data) { if (data == "OK") { var score = parseInt(\$('#a_score_'+aid).text()) + 1; \$('#a_score_'+aid).html(score); } }); } }); }); © 2022 OneMinuteCode. All rights reserved. ```