1 / 11
Oct 2009

include

//#include
using namespace std;
int main()
{
int cases,n,i,j,mens[1001],wmens[1001];
long int sum[1001];
cin>>cases;
for(i=0;i {
cin>>n;
for(j=0;j cin>>mens[j];
for(j=0;j {
cin>>wmens[j];
sum[i]=sum[i]+mens[j]*wmens[j];
}
}
for(i=0;i {
cout<<"\n"< }
// getche();
return 0;
}

whats the wrong answer in this code

  • created

    Oct '09
  • last reply

    Jul '14
  • 10

    replies

  • 342

    views

  • 6

    users

What you did, I fear, is not enough for the problem.
Also.. the printing part.. Each line should end with a '\n'

1 month later

No after "\n", newline ,its not working.
Even My code:

include

using namespace std;
int main()
{
int n,t,sum,i,j,k;
cin>>t;
while(t>0)
{

      cin>>n;
      sum=0;
      int m[n];
      int w[n];
      for(i=0;i<n;i++)cin>>m[i];
      for(j=0;j<n;j++)cin>>w[j];
      for(k=0;k<n;k++)
      sum=sum+(m[k]*w[k]);
      cout<<sum<<endl;
      t--;

}

return 0;
}

is producing wrong output.......wats wrong in this..?

yup.......ma code is here..

include

using namespace std;
int main()
{
int n,t,temp=0,sum,i,j,k;
cin>>t;
while(t>0)
{

      cin>>n;
      sum=0;
      int m[n];
      int w[n];
      for(i=0;i<n;i++)cin>>m[i];
      for(j=0;j<n;j++)cin>>w[j];

for(i=1;ifor(j=0;j<(n-i);j++)
if(m[j]>m[j+1])
{
temp=m[j];
m[j]=m[j+1];
m[j+1]=temp;
}

for(i=1;jfor(j=0;j<(n-i);j++)
if(w[j]>w[j+1])
{
temp=w[j];
w[j]=w[j+1];
w[j+1]=temp;
}
for(int h=0;h sum=sum+(m[h]*w[h]);
cout< t--;
}

return 0;
}

question question question

Just read through each line of your code slowly. The mistake is rather obvious wink

4 years later

Wczytujesz pierwszą liczbą i sprawdzasz czy jest pierwsza - tu jest błąd. W pierwszej linii jest liczba testów a nie liczba do sprawdzenia. Ta liczba przekracza zakres Twojej tablicy stąd SIGSEV (który nie jest błędem kompilacji a błędem wykonania).