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 3 days ago.
Improve this question
I need to do an exercise: input 2 integers a ,b and print the sum , difference , product , quotient but the window after running is completely blank, what is the problem?
#include<stdio.h>
int main(){
int a, b;
int sum = a + b, diff = a - b, pro = a*b, quotient = a/b;
scanf("%d%d", &a, &b);
printf("enter a and b ",a,b);
printf("sum is %d\n diff is %d\n pro is %d\n quotient is la%d\n",sum,diff,pro,quotient);
return(0);
}
the window after running is completely blank, what is the problem?
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 1 year ago.
Improve this question
I have a problem that this code doesn't end with output.
I appreciate if help me.
#include <stdio.h>
int main(){
int number,counter=0;
scanf("%d",&number);
while (number!=0){
number=number/10;
counter++;
}
printf("the number has %d digits",&counter);
return 0;
}
You should remove "&" from your printf statement.
& is for scanning not printing
the correct form is :
printf("the number has %d digits",counter);
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
Im new to C.
I dont understand i have the " in front of the %d
#include <stdio.h>
int x,y;
int main(void)
{
printf("Indtast 2 numre du vil bytte rundt på \n");
scanf("%d", &x);
scanf("%d", &y);
printf("Dette er dine numre byttet rundt! %d, %d", y, x);
return 0;
}
The code you posted here looks fine. However, looking at the title, you seem to have missed double-quotes around %d on line 7. Save the code you just posted, and recompile. Next time, please post the compiler you are using, too.
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 3 years ago.
Improve this question
Write a C program to calculate (x^n)/(n!) where x is a floating point number and n is an integer greater than or equal to zero.
I coded the following:
#include<stdio.h>
#include<math.h>
void main()
{
float x,p;
int i,n,f=1;
printf("Enter the value of x,n\n");
scanf("%d %d",&x,&n);
if(n>0)
{
for(i=1;i<=n;i++)
{
f=f*i;
}
p=(float)pow(x,n)/f;
printf("The value of p is %.3f",p);
}
if(n==0)
{
p=(float)pow(x,n)/1;
printf("The value of p is %d",p);
}
getch();
}
But this is not running well. Where have I gone wrong?
PS: Edit
In your question I have recognize 3 problems.
main problem is scanf("%d %d",&x,&n); should be change into scanf("%f %d",&x,&n);
because x is `float type #dragosht has mentioned it.
printf("The value of p is %d",p); should be correct as printf("The value of p is %f",p); beacause p is also float type.
It is better to set p = 0; at the beginning because you did not assign value to p using keyboard. There for some times you will get corrupted values because of this.
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
#include<stdio.h>
void main()
{
int a,b,p;
printf("Enter values of a and b");
scanf("%d%d", &a, &b);
p=printf("a=%d b=%d p=%d",a,b, p);
}
This is the code for my question. Consider the inputs as a=2 and b=3.
Change:
p=printf("a=% b=%d p=%d",a,b, p);
to:
p = printf("a=%d b=%d\n", a, b); // <<< fix format string
printf("p=%d\n", p); // <<< print `p` *after* you have assigned a value to it
Please also enable compiler warnings from this day forward - any good compiler would have pointed out all of the above errors to you at compile-time.
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 have only used the function twice and it displays the aforementioned error. Can someone explain as to why the compiler does that?
void printrandom()
{
int x = (rand(5)+1);
int y = (rand(5)+1);
printf("%d and %d - a total of %d", x, y, (x+y));
}
It is actually rand(void), which is why you are getting that error.
Try int x = (rand() % 5) + 1;
EDIT as Daniel points out, using % will actually affect the probability. See his link for how to address this issue.
Declaration for rand() function is
int rand(void);
This means that it takes no arguments. Remove 5 from rand. If you want to generate random numbers from 1 to 5, the you can do this as
int x = rand()%5 + 1;