To calculate the cube of using pow [closed] - c

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;
}

Related

The program is not terminating [closed]

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.

avarage result always 0.0 what is wrong with my code? [closed]

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 &.

Error in a recursive function to print out a series [closed]

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
So, I am supposed to print out the following series using a C program:
I decide to use a recursive approach and come up with this code:
#include<stdio.h>
float series(int n, float x)
{
float prod;
if(n==1)
return 1;
else
{
prod = (x*x)/((2*n-2)(2*n-3)); //line 10
return prod*series(n-1,x);
}
}
int main()
{
int n;
float x;
printf("\n Enter the values of n and x : ");
scanf("%d %f",&n,&x);
printf("\n The series is :");
for(int i=1;i<=n;i++)
printf(" %f,",series(i,x));
printf("\n\n");
return 0;
}
But this gives an error on line 10:
error: called object type 'int' is not a function or function pointer
I don't see any syntactical error on the line. It would be great if you could point it out.
Thank You!
prod = (x*x)/((2*n-2)(2*n-3)); //line 10
should be
prod = (x*x)/((2*n-2)*(2*n-3)); //line 10
The compiler sees this as a function call where 2*n-2 is the function pointer and 2*n-3 is the argument.

output is address instead of values [closed]

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.

printing too much stars [closed]

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.

Resources