Bug Fix

Moving on to some programming problems. Learned if-else, loops, arrays and so on but couldn’t find bugs in a code. If any one could help me please comment.

Problem: Have to make a reverse array and print it but not making two different arrays.

input: 1 2 3 4 5 6 7 8 9 10

output: 10 9 8 7 6 5 4 3 2 1

Solve what I made:

#include <stdio.h>

int main()
{
int ara[10];

int i,j, temp;

for(i=0;i<10;i++){
scanf(“%d”,& ara[i]);
}

for(i=0, j=9; i<10; i++, j–){

temp = ara[i];
ara[i] = ara[j];

ara[j] = temp;

}
for(i=0;i<10;i++){
ara[i]=ara[j];
}

for(i = 0;i<10;i++){
printf(“%d\n”, ara[i]);
}

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s