avarage result always 0.0 what is wrong with my code? [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 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 &.

Related

Warning: implicit declaration of function 'toupper' [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 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;
}

To calculate the cube of using pow [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 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;
}

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.

The program is error free but doesn't run fully and stops at a stage why? [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 6 years ago.
Improve this question
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char name[10]; int siblings;
printf("enter the name\n");
scanf("%s",name);
if (strcmp(name,"larry")!=0)
{
printf("you are not larry");
}
else
{
printf("you are larry\n");
printf("how many siblings do you have\n");
scanf("%d",siblings);
fflush(stdin);
printf("you have %d siblings Mr.%s\n",siblings,name);
}
getchar();
return 0;
}
/This is the program running well till it prints "how many siblings do you have" and then stops working/
The code scanf("%s",name); is okay because it is a string but, this one is not because it is not a string scanf("%d",siblings);. You will learn more about it when you reach pointers and why you can just you can just remove the & sign for char[] or with arrays. That is a runtime error by the way. That is why you get the error while the program is already running.

Why it doesn't work ( C Lang in Dev C++ ) [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 years ago.
Improve this question
Please tell me, what is wrong here,it compiles but console crashes when i enter the number. I don't know what to write next, i will just write something to make my post possible.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
unsigned int i,l,p,w;
printf("Enter natural number excluding 0: ");
scanf("%d",l);
p = 1;
for(i=1;i<=l;i++)
{
p=p*i;
}
w=p;
printf("\nFactorial of entered number %d",w);
return 0;
}
scanf("%d",l); you need to insert the address of l, which is &l.
You should also use %u for unsigned ints, not %d.

Resources