Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Following is the code to obtain matrix like 11 12 13 etc... I am not getting desired results since long. Help me with the solution.
#include<stdio.h>
int main() {
int i,j;
for(i=1;i<5;i++){
for(j=1;j<5;j++){
printf("%d %d",i,j);
}
printf("\n");
}
fgetc(stdin);
}
Probably because you have a space between the digits:
printf("%d %d",i,j);
Shouldn't it be:
printf("%d%d ",i,j);
for your desired output?
Shouldn't printf("%d %d",i,j); actually be printf("%d%d ",i,j);?
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
#include<stdio.h>
int main(){
int a,b[101],i,j,sum=0;
scanf("%d",&a);
for(i=0;i<a;i++){
for(j=0;j<3;j++){
scanf("%d",&b[j]);
sum=sum+b[j];
}
}
if(sum==0) printf("YES\n");
else printf("NO\n");
return 0;
}
outputs are showed perfectly but online judge didn't accept.
online judge message"wrong answer on test 81".
link of problem"http://codeforces.com/problemset/problem/69/A"
The problem is asking to check if the sum of all vectors is zero.
Sum of vectors is element-wise addition of vectors, not simple summation of all elements.
Your program will fail in, for example, this case:
1
1 0 -1
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
#include <stdio.h>
#define number 0
main()
{
int i;
for (i = 0; i < 5; i++)
{
number++;
}
printf("Number is: %d", number);
}
No, 0 is substitued for number by the preprocessor before the compiler gets to work.
The compiler issues a diagnostic when it sees 0++;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So I need to calculate the determinant matrix on 2x2 matrix, simple one..
If you can, please write the code, because i don't understand like in the other thread, it's like i'm reading an English Literature + Code..
#include<stdio.h>
int main(){
int x[2][2]={{1,2},{3,4}};
int i,j,d;
for(i=0;i<=1;i++){
for(j=0;j<=1;j++){
printf(" %d ", x[i][j]);
}
printf(" \n");
}
return 0;
}
Thank You!
You don't need a loop to calculate the determinant of a 2x2 matrix, simply use:
int result = (x[0][0] * x[1][1]) - (x[0][1] * x[1][0]);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
#include <stdio.h>
int main()
{
int var=0;
for(; var++; printf("%d",var));
printf("%d", var);
}
Please explain to me this C code. How is the output 1?
You might be confused because of the wrong code indentation. Your code is:
for(; var++; printf("%d",var))
;
printf("%d", var);
So you always get the output of the second printf. As var is initialized to 0 and var++ (the for-condition) is always executed, you end up with var==1.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am getting an error saying: Thread stopped.....access violation at 0x6:read of address 0x6.
However my code doesn't have such address.
#include<stdio.h>
#include<conio.h>
void main ()
{
int i,j,A[4][5],c=0;
for(j=0;j<5;j++)
for(i=0;j<4;i++)
{
A[i][j]=c;
c++;
}
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
printf("%d\t",A[i][j]);
printf("\n");
}
getch();
}
I was asked to enter a double array column by column instead of row by row, and I want to verify my method so I tried to print it out but had no luck doing so.
for(i=0;j<4;i++)
^^
Shouldn't this be:
for(i=0;i<4;i++)
j<4 is always true once it enters inner the loop for the first time and is the reason for memory access violation.