|
|
back to boardDiscussion of Problem 1068. SumWhat's wrong with my code? #include<stdio.h> #include<conio.h> int main() { int a, sum = 0; scanf("%d",&a); if( a > 0 ) { for ( int i = -1; i <= a; i++) sum += i; } else { for (int i = 1; i <= -a; i++) sum += i; sum = 1 - sum; } printf("summa ravna %d",sum); getch(); } Re: What's wrong with my code? Posted by tomkus 29 Nov 2012 02:23 first: printf("summa ravna %d",sum); use just: printf("%d",sum); second: don't use: getch(); third: if A>0 sum from 1, not from -1 |
|
|