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
Actually right now i am learning c and doing an excercise of looping and got messed up in a question.
my code is:
#include<stdio.h>
void main()
{
int i,j,k,spc,k;
printf("\enter the number of rows:");
scanf("%d",&rows);
spc=rows+4-1;
for(i=1;i<=rows;i++)
{
for(k=spc;k>1;k--)
{ printf(" ");
}
for(j=1;j<=i:j++)
printf("*");
printf("\n")
spc--;
}
}
https://www.w3resource.com/c-programming-exercises/for-loop/c-for-loop-exercises-14.php
and this is the reference for the answer by them whose excercise i am doing right now.
can you see any difference bw these codes.
please help me.
thank you
as i can see, you have small errors which you need to fix ,
first is, int i,j,k,spc,k;, here, 'k' is written twice, next is scanf("%d",&rows); but, rows is not declared anywhere, in this line,for(j=1;j<=i:j++), you missed a semicolon and added colon instead, so replace it with for(j=1;j<=i;j++) and the last one is, printf("\n") ,in this line, you missed a semicolon! and for the desired output, you just need to add a space in printf("*"); ,i.e, printf("* ");.Thats it.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I can't understand this code.
please help me in explaining how this code works.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
P
getch();
}
I'll play this silly game. Your teacher is having a joke with you.
By the magic of https://www.naclbox.com/gallery/turboc :
Consider:
Then note the hidden macro definition on line 6 (note the column number):
Voila!
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 7 years ago.
Improve this question
link to the code: http://gyazo.com/f0f4004eb606607ecaa021b5e22e6e06
I am getting the following error when i am running th code.
"error: expected identifieror '(' "
I use gedit to write this code.
I would appreciate some support guys ;)
Thanks in advance!,
Vicente
There's shouldn't be a semicolon in the int main(void); declaration.
Try replacing line 4 with: int main(void) instead.
Also, please read up on C function declaration syntax
https://msdn.microsoft.com/en-us/library/c4d5ssht.aspx.
int main(void);
^you should not do this.
And you forgot to put ; after this statement -
int height=n
And also n is not declared in your program.
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'm relatively new to coding and am having a problem with a very small piece of code. It seems as if this should be simple to resolve, and I'm bothered that I can't figure it out myself. I was building a program to conduct a variety of conversions that I have to perform all the time and it was ouputting garbage. I backtracked and am testing all my functions. It seems that my functions weren't working, so I began testing each individual function as to whether or not it was correct.
I have one conversion here that I was running as a test code. It should take user int input and calculate ft from an input of miles. That seems pretty simple right? I thought so to.
Can someone please provide some insight as to why the very simple code below doesn't work?
#include <stdio.h>
int main(void)
{
float miles;
printf("Enter value in miles: ");
scanf(" %d", &miles);
printf("\n\n%.0d miles is equal to %.0d ft.", miles, ((miles)*5280));
return(0);
}
Use %f instead of %d in scanf function
You need just an integer. Change
float miles;
into
int miles;
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'm passing in an int to a function in my lame program. It's passing in a number to convert it to a binary representation as an int array.
typedef int bool;
bool* conv2bin(int num)
{
blah blah blah return binary as bool array
}
I pass in 78 and if I printf() immediately after it's passed in, I get 781237412753-124?
I'm new to C (coming from C++) so please tell me if I'm doing something really dumb?
This seems like it should be really easy but it isn't...?
EDIT:
Have I done goofed:
printf("%d", num);
EDIT 2:
It has to be something with the int because at the end of the function, it checks to see if we subtracted numbers sufficiently to get to num==0 but it says we're not at 0. It's doing really weird things. It also says that the binary is 0000000001001111, and it should be 0000000001001110.
Edit 3:
Wow I suck. Thank you Floris! It's been a long day.
Guessing hereā¦
Your printout starts with the correct two digits: 78.
But if you do not include a \n at the end of your formatting string, then the next thing you print will be concatenated. As will the next thing, and the next.
I suspect your problem will disappear when you change your print statement to
printf("%d\n", num);
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
can someone please tell me how to check in c that a particular letter was pressed ?
I want to check if the letter 'r' was pressed. here is a small part of my code, where I need to check if it was pressed.
ch = getch();
if(ch==r)
i=1;
else
i=2;
the program considers the 'r' in my 'if' as a variable, but I want it to be considered as a letter so I would be able to check if it was pressed. can someone please tell me how to do that ?
Put the 'r' in single quotes:
ch = getch();
if(ch=='r')
i=1;
else
i=2;