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;
scanf("%d", &C);
scanf("%s", &T);
for(x=0;x<=11;x++)
{
for(y=0; y<=11; y++)
{
scanf("%lf", &M[x][y]);
if(y==C)
a+=M[x][y];
}
}
if(T[0]=='S')
printf("\n%.1lf\n",a);
else if(T[0]=='M')
{
a=a/12.0;
printf("%.1lf\n",a);
}
return 0;
}
Why this code show WA
ReplyDelete#include
#include
using namespace std;
int main()
{
double a[12][12],sum=0.0;
int i,j,n;
cin>>n;
char ch;
cin>>ch;
for(i=0;i<12;i++){
for(j=1;j<12;j++){
cin>>a[i][j];
if(j==n){sum+=a[i][j];}
}
}
double av= sum/12.0;
if(ch=='S')
printf("%.1lf\n",sum);
else if(ch=='M') printf("%.1lf\n",av);
}