Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I did this and I think it should work:
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++);
{
for(j=1;j<=5;j++);
{
printf("%d",i*j);
}
}
return 0;
}
But it just prints out 36...
What am I doing wrong?
Remove the two extra ;s:
for(i=1;i<=5;i++);
^
{
for(j=1;j<=5;j++);
^
As others have pointed out, the semicolons before the opening braces of your for loops are preventing the printing.
Additionally, if you want the output to appear as a matrix, you'll want to printf a newline after your first for loop:
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
printf("%d",i*j);
}
printf("\n");
}
return 0;
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
#include<stdio.h>
int reverse(int );
int main()`
{
int num,rem,r;
printf("Enter a number:");
scanf("%d",&num);
r=reverse(num);
r=reverse(num);
return 0;
}
int reverse(int num)
{
int rem,rev=0;
while(num>=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
return rev;
}
Its not showing any errors and after entering the number the program stay still, its neither showing any output nor terminating
You have not used printf for output.
r = reverse(num);
printf("%d",r);
return 0;
Use this.
And also while condition should be
while (num > 0)
There is no need to call reverse function twice as well.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
#include <cs50.h>
#include <stdio.h>
int main(void);
{
int i;
do
{
i=get_int("Height:");
printf("Height:%i./n")
}
while(i>0 && i<9);
for(int j=1;j<9;j++)
{
for(int z=int i-1;z<9;z++)
{
printf("../n");
}
printf("#./n");
}
i have been trying to solve for a long time but it is not working. the error it is showing is:
mario.c:5:1: error: expected identifier or '('
{
^
1 error generated.
can anyone please tell my mistake
i am supposed to form the blocks of mario
you added a ; after main declaration and you missed one after this printf printf("Height:%i./n")
this ; should be removed int main(void);
and add one } at the end of main.
also you has to remove second int here for(int z=int i-1;z<9;z++) this should be for(int z=i-1;z<9;z++).
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i,limit,sum=0;
int a[100];
setbuf(stdout,NULL);
printf("enter the limit");
scanf("%d",&limit);
printf("enter the values");
for(i=0;i<limit;i++)
{
scanf("%d",&a[limit]);
}
for(i=0;i<limit;i++)
{
sum=sum+a[i];
}
printf("the sum is : %d",sum);
return 0;
}
Output:
enter the limit3
enter the values3
3
3
the sum is : 19265880
The actual output should be 9
for(i=0;i<limit;i++)
{
scanf("%d",&a[limit]); //replace limit with i
}
You can see that scanf is reading into the array a[limit] instead of a[i]. This is causing the issue.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
The prototype (void example();) I have mentioned for the program is correct, but the compiler is giving garbage value instead of correct values in the output.
What codes should be added or removed?
Here is my code:
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
void example()
{
static int x = 10;
x=x+10;
printf("\n%d",&x);
}
int main()
{
int i;
for(i=0;i<=3;i++)
{
example();
}
getch();
return 0;
}
You are using an adress of a variable where printf wants just the value:
printf("\n%d",&x);
->
printf("\n%d",x);
Your result might also be improved by using "%d\n" instead.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
(Write a C function that should check if a matrix (4x5) is sparse or not. Knowing that: sparse matrix is a matrix that has zeros more than the half of its size.)
That's a problem for a sheet in out subject
here is my code:
#include <stdio.h>
#include <stdlib.h>
int Spare(int [4][5]);
int main()
{
int arr[4][5];
int m,n;
for(m=0;m<4;m++){
for(n=0;n<5;n++){
scanf("%d ",&arr[4][5]);
}
}
Spare(arr[4][5]);
return 0;
}
int Spare(int Arr[4][5]){
int i,j;
int zerocount=0;
for(i=0;i<4;i++){
for(j=0;j<5;j++){
if(Arr[i][j]==0){
zerocount++;
}
}
}
if(zerocount>=10) return 1;
else return 0;
}
Its Running but after the user enter inputs of array it stops working!
Any Help Guys?
Change scanf("%d",&arr[4][5]) into scanf("%d",&arr[m][n]). You are just storing the input in arr[4][5] everytime in the loop.
The Spare(arr[4][5]) pass the element of fifth row and sixth column only which doesn't exist.
The Spare function expects an array as parameter and you are passing the single element only.
The function call must be done in this way: Spare(arr)