hey,when i run the below code it runs successful but when i submit it gets wrong answer…
the same problem occurs with me for many programs.i need help because i occurs many time. i m beginner.
the link for code is
https://www.codechef.com/viewsolution/7940047
enter code here
#include<stdio.h>
int main()
{
int t,i,j;
unsigned long a[100005],b[100005],n;
long long sum=0,x;
scanf("%d",&t);
while(t>0)
{
scanf("%lu",&n);
for(i=0;i<n;i++)
{
scanf("%lu",&a[i]);
}
for(i=0;i<n-1;i++)
{
b[i]=a[i+1]-a[i];
}
x=0;
for(i=n-2;i>=0;i--)
{
x=x+b[i]*(n-1-i);
sum=sum+x;
}
printf("%lli",sum);
t--;
}
return 0;
}
your given link is not working…
if you really want to post code here please make sure it should be indentend…
#include<bits/stdc++.h>
using namespace std;
int main(){
//your code is here
return 0;
}
you can do this using ctrl+k or provide 4 space before any line of code…
hope it help you…
1 Like
Your solution is not public but you can get help from this link
My link
Okay…simple mistakes…Sum should be zero each time new test case begins…so put that sum=0 inside the while loop…and also print a new line after each output…try,it will work
1 Like
please post code with indentation or don’t
link is enough…
okk…now it is with indentation…
1 Like
Just a suggestion…you can accept the answers given by others if it works for you to confirm that the problem is solved…