Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { double a=0.0, M[12][12]; char T[2]; int C,x,y,z,p=1; scanf("%s", &T); for(x=0;x<=11;x++) { for(y=0; y<=11; y++) scanf("%lf", &M[x][y]); } for(z=0; z<=11;z++) { for(C=p; C<=11;C++) a+=M[z][C]; p++; } if(T[0]=='S') printf("%.1lf\n",a); else if(T[0]=='M') { a=a/66.0; printf("%.1lf\n",a); } return 0; }
Why my code don't work?
ReplyDelete#include
#include
#include
int main()
{
int i, j;
char escolha[2];
float m[12][12], soma=0;
scanf("%s", &escolha);
for (i=0; i<12; i++){
for (j=0; j<12; j++){
scanf("%f", &m[i][j]);
if (j>i) soma+=m[i][j];
}
}
if (strcmp(escolha, "S")==0) printf("%.1f\n", soma);
else printf("%.1f\n", soma/12);
return 0;
}
it will be %lf not %f
DeleteBecause you divided it by 12, it will be different.
ReplyDelete#include
ReplyDeleteint main()
{
int i,j;
double a[12][12],sum=0,x=1,p;
char c;
scanf("%c",&c);
for(i=0;i<12;i++)
for(j=0;j<12;j++)
{
scanf("%lf",&a[i][j]);
}
for(i=0;i<12;i++)
{
for(j=i+1;j<12;j++)
{
x=x+1;
sum=sum+a[i][j];
}
}
if(c=='S')
printf("%.1lf\n",sum);
else if(c=='M')
printf("%.1lf\n",p=sum/x);
return 0;
}
#include
ReplyDeleteint main()
{
int i,j;
double a[12][12],sum=0;
char c;
scanf("%c",&c);
for(i=0;i<12;i++)
for(j=0;j<12;j++)
scanf("%lf",&a[i][j]);
for(i=0;i<12;i++)
{
for(j=i+1;j<12;j++)
sum=sum+a[i][j];
}
if(c=='S')
printf("%.1lf\n",sum);
else if(c=='M')
printf("%.1lf\n",sum/66);
return 0;
}
why my code gets 75% wrong answer?
ReplyDelete#include
#include
using namespace std;
int main()
{
double M[12][12];
char T[2];
cin>>T;
int p=1;
for(int i=0;i<=11;i++)
{
for(int j=0;j<=11;j++)
{
cin>>M[i][j];
}
}
double sum=0.0;
for(int i=0;i<=11;i++)
{
for(int j=p;j<=11;j++)
{
sum+=M[i][j];
}
p++;
}
if(T[0]=='S')
{
cout<<setprecision(1)<<sum<<endl;
}
else if(T[0]=='M')
{
sum=sum/66.0;
cout<<setprecision(1)<<sum<<endl;
}
return 0;
}
#include
ReplyDeleteint main()
{
double A[12][12],s=0;
int i,j;
char X[2];
scanf("%s",&X);
for(i=0;i<12;i++)
{
for(j=0;j<12;j++)
{
scanf("%lf",&A[i][j]);
if(i<j)
s+=A[i][j];
}
}
if(X[0]=='S')
printf("%.1lf\n",s);
else if(X[0]=='M')
printf("%.1lf\n",s/66.0);
}