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.
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 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 3 years ago.
Improve this question
my function:
int compare(int A, int B){
if(A>B){
return A
}
else {
return B
}
}
int main(void)
{
int A;
int B;
scanf("%d", &A);
scanf("%d", &B);
compare (A,B);
}
but it is not returning, if i write print instead of return however, it works
It is correctly returning[1]; you simply don't do anything with the returned value. For example, if you wanted to print the returned value to stdout, you could use the following:
printf("%d\n", compare(A,B));
If it wasn't for the missing includes, the stray semi-colon, the two missing semi-colons, and the missing right brace that prevent the code from even compiling.
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 6 years ago.
Improve this question
I'm reading data from standard input one character at a time and outputting the results to standard output. Every 10 characters, I want to have a new line. For example:
Input-
123456789101112
Output-
1234567891
01112
This is what I have so far, but it doesn't work.
if(numChars = 10) {
printf("\n");
numChars = 0;
}
#include <windows.h>
int main()
{
char test[] = "123456789101112123133431234567891011121231334312345678910111212313343";
int i = 0;
while (i < strlen(test))
{
printf("%c", test[i++]);
if (i % 10 == 0) {
printf("\n");
}
}
return 0;
}
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
How this answer is come
#include<stdio.h>
#include<conio.h>
int main() {
int i, sum;
for (i = 0, sum = 0; i < 10; i++)
sum += i;
printf("%d", & sum);
return 0;
}
Output
2358648
You are printing addess instead of value
just remove & in printf
printf("%d",sum);
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
I type this code on Ubuntu 14.04
#include<stdio.h>
int main() {
int i, j, n;
scanf("%",&n);
for (i=0;i<=n;i++){
for (j=0;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
but it print too much stars and it Continue until I close it.
Should be:
#include<stdio.h>
int main() {
int i, j, n;
scanf("%d",&n);
for (i=0;i<=n;i++){
for (j=0;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
You forgot to tell scanf you were reading in an integer by using the %d argument
There is mistake in
scanf("%",&n);
it will be:
scanf("%d",&n);
to tell the complier that the value of n is an integer type.