C while loop not executing [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm learning c and I can't figure out the problem with this code:
#include <stdio.h>
int main(){
int i = 0;
while(i > 10){
printf("hello");
i++;
}
getch();
return 0;
}
I don't get any errors and have tried running it on codeblocks and wxdev c++. So is there something I'm doing wrong. Thanks.

You set
i = 0;
and then test
i > 10
which is always false.
You might want
while (i < 10)
instead.

I is not greater than 10 so it doesnt meet the requirement to enter the while loop

while(i > 10){
...but i is 0 so it's false and skips.
You probably meant to instead write;
while(i < 10) {

Reason: i is not greater than 10.

Related

C to MIPS convert [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Can anyone help me convert the C code below to MIPS code? I'm supposed to use recursion and get 21 - 2 as the final answer. Thanks!
/*
x is a pointer to a linked list node and is not null.
Return the min value stored in the linked list.
Assume each node is stored in memory as an int (value) followed by a pointer to the next node (next), each a word wide.
You must write it with recursion. */
int findMin(node *x) {
if(x->next == NULL)
return x->value;
else {
int min = findMin(x->next);
if(min < x->value)
return min;
else
return x->value;
}
}
Here you are:
mips-linux-gnu-gcc -S -o foo.asm foo.c

Online Judgement System - Why am I getting Wrong Answer for this thread? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Original page: http://acm.whu.edu.cn/learn/problem/detail?problem_id=1036
This should be a simple Dynamic Programming problem. I figured out the solution to be the following:
int main(void)
{
double d[501];
int i;
d[0] = d[1] = 1.;
d[2] = 2.;
for(i = 3; i<=500; i++)
d[i] = d[i-1] + d[i-2] + d[i-3];
int n;
while(scanf("%d", &n) == 1) {
if(n == 0) return 0;
printf("%.0lf\n", d[n]);
}
return 0;
}
But Wrong Answer reported after submission. I really don't know why.
double is not enough for the precision
you should use high-precision to solve it
Decimal point maybe. printf("%.0lf\n", 1.0); will print 1.0 but system may wait for 1.

Floating point bug common to different languages? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
#include<stdio.h>
void main()
{
float i,j;
i=??;
j=i+1;
if(i==j)
printf("Bug");
}
My teacher gave me this qns to find the value of i so that the printf executes.
He said this is a common bug in a lot of languages.
Always try the boundaries for odd behavior. This worked for me:
#include <float.h>
int _tmain(int argc, _TCHAR* argv[])
{
float i,j;
i = FLT_MAX;
j = i + 1;
if(i == j)
{
printf("they're the same");
}
return 0;
}

meaning of this code [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
int main()
{
int x = 2, y = 6, z = 6;
x = y == z;
printf("%d", x);
}
== has higher precedence than =, and y==z is 1.
I will end the answer there, because this looks like homework.
http://codepad.org/fp4ZYJX5
The output is:
1
Have a look at this, which explains a similar, yet more complex question and will answer yours as well.
Output is 1
If you want more help we can give you

Multiplication table in c [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Tips on how to do multiplication table in c??
ummm... two (nested) loops?
This should work. Really.
printf("2x1=2");
printf("2x2=4");
printf("2x3=6");
printf("2x4=8");
...
You should read books this is very basic things of programming you must clear this things yourself.
I personally recommend you not just to post here and get answer
Try reading and try developing by yourself before you post it overhere.
http://www.cprogramming.com/tutorial/c/lesson3.html
int main () {
int n = 10;
int i, j;
// Print row labels
for (i=1; i<=n; i++) {
for (j=1; j<=n; j++) {
//printf("\t%d",i*j);
//Do something here to get it working.. :-)
}
printf("\n");
}
}
You have to use 2 nested loops and if you want to make it more organized, use a two-dimensional array.

Resources