Sums in a Triangle -- Please help--Important

I am getting wrong answer.kindly help me in finding out the error.

The code is at

Thank you :slight_smile:

Poor you, well it took me a while. you have declared n as ‘short int’ but you scan it as ‘scanf("%d",&n)’, which is for scanning ints. this generates a warning but alas people ignore warnings. that’s what produced the error.
so what you can do:

  1. declare n as int
  2. use cin instead of scanf
  3. use the correct scanf format i.e. scanf("%hd",&n)

Even I learned something new from this.

1 Like