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.
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 11 months ago.
Improve this question
#include<stdio.h>
int main() {
char l,u;
printf("Enter any lowercase number: ");
scanf(" %c",&l);
u = toupper(l);
printf("The uppercase number is: %c\n",u);
return 0;
}
The toupper() function is declared in the <ctype.h> header file. So you have to include that at the top.
#include <stdio.h>
#include <ctype.h>
int main() {
char l,u;
printf("Enter any lowercase number: ");
scanf(" %c",&l);
u = toupper(l);
printf("The uppercase number is: %c\n",u);
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 12 months ago.
Improve this question
what is wrong with the code since it is not giving the value for cube
#include<stdio.h>
#include<math.h>
int main(){
int number;
printf("Give The Number:\n");
scanf("%d",number);
int cube;
cube = pow(number,3);
printf("Cube : %d/n,cube);
return 0;
}
change
scanf("%d",number);
to
scanf("%d",&number);
you are not printing it. also when you post questions here also post the error that your code gives.
#include<stdio.h>
#include<math.h>
int main(){
int number;
printf("Give The Number:\n");
scanf("%d", &number);
int cube;
cube = pow(number,3);
printf("Cube : %d", cube);
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 1 year ago.
Improve this question
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n,i;
float num[100],sum=0.0,avg;
printf("please enter a number between 1-100: ");
scanf("%d",&n);
while(n<1||n>100){
printf("wrong number, enter again: ");
scanf("%d",&n);
}
for(i=0;i<n;i++){
printf("%d. number: ",i+1);
scanf("%f",&num[i]);
sum+=num[i];
}
avg=sum/n;
printf("avarage %.2f",&avg);
return 0;
}
In last printf("...", <float>) you shold not send an adress of sum. Remove &.
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;
}