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(x==C) a+=M[x][y]; } } if(T[0]=='S') printf("%.1lf\n",a); else if(T[0]=='M') { a=a/12.0; printf("%.1lf\n",a); } return 0; }
char T[2];
ReplyDeletewhy in this code a character array has been read as input instead of reading a single character ?
Yeah!!! You can do this as you say.
DeleteThis is possible one.
I did this because i am comfortable in such way.
why this code went wrong?
ReplyDelete#include
int main()
{
int a[12][12],i,j,n;
double sum;
scanf("%d",&n);
char ch[100];
gets(ch);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&a[i][j]);
}
}
if(ch=='S'){
sum=0;
for(j=0;j<12;j++)
{
sum=sum+a[2][j];
}
printf("%lf\n",sum);
}
else if(ch=='M')
{
sum=0;
for(j=0;j<12;j++)
{
sum=sum+a[2][j];
}
printf("%.1lf\n",sum/12.0);
}
return 0;
}
ur code is not working bcz string(%s)...u should use char(%c)
ReplyDelete#include
int main()
{
int i, j, a;
double x[12][12], m=0;
char ch;
scanf("%d %c", &a, &ch);
for(i=0;i<12;i++)
{
for(j=0;j<12;j++)
{
scanf("%lf", &x[i][j]);
if(i==a)
m+=x[i][j];
}
}
if(ch=='S')
printf("%.1lf\n", m);
else if(ch=='M')
printf("%.1lf\n", m/12.0);
}