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 days ago.
Improve this question
the whole code is
#include <stdio.h>
void pytho( int arr[],int n)
{
int i,j,k,d,b,c;
i=0;
j=i+1;
k=j+1;
if(i<j)
{
j++;
if(j<k)
{
k++;
d=arr[i]*arr[i];
b=arr[j]*arr[j];
c=arr[k]*arr[k];
if(d==b+c)
{
printf("%d = %d + %d",d,b,c);
}
else
{
printf("no elemnts found");
}
}
}
}
void main()
{
int n;
int arr[10];
arr=[2,4,20,16,3,416,24,10,5];
pytho(arr,n);
return 0;
}
there are 3 errors showing up
/tmp/c1cHuURRE3.c:34:9: error: expected expression before '[' token 34 | arr=[2,4,20,16,3,416,24,10,5]; | ^
/tmp/c1cHuURRE3.c:36:12: warning: 'return' with a value, in function returning void 36 | return 0; | ^
/tmp/c1cHuURRE3.c:30:6: note: declared here 30 | void main() | ^~~~
i was expecting the program to find 3 numbers that follows the pythagoras theorem from the array
so the return 0 isnt returning any value cause of that
and it says void main (declared here) and i dont understand what that even means
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 6 months ago.
Improve this question
So I got this question in my end-sem:
//The value returned by sam(3,0) of the below function is:
#include <stdio.h>
int sam(int n,int a)
{
if(n==0)
return a;
else
{
a+=n;
sam(--n, a);
a+=n;
}
}
I calculate using Tree-method and got the answer as 6. But if I compile and directly print return I get 2.
int main()
{
printf("%ld",sam(3,0));
return 0;
}
OUTPUT: 2
I checked again and again with what is wrong and couldn't understand. The mystery is if I print(a) just before it returns. It returns 6 (what I calculated).
#include <stdio.h>
int sam(int n,int a)
{
if(n==0){
printf("%d",a); //Check the change here
return a;
}
else{
a+=n;
sam(--n,a);
a+=n;
}
}
int main()
{
sam(3,0);
return 0;
}
OUTPUT: 6
If I explain this I get 4 marks. Enough to change my grade
With a bit of formatting assistance, please note that the below function only explicitly returns when n is 0. Otherwise it performs recursion, but uselessly since it never returns any value created by the recursion.
As a result, you find yourself in the realm of undefined behavior.
#include <stdio.h>
int sam(int n, int a) {
if (n == 0)
return a;
else {
a += n;
sam(--n, a);
a += n;
}
}
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.
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
hello=) with this following code i get the exception
error: expected ‘;’ before ‘printf’
#include <stdlib.h>
#include <stdio.h>
int main() {
int i;
scanf("%i", &i);
for(int i=0 ; i<10; i++){
if(i==1) printf("one");
else if(i==2) printf("two");
else if(i==3) printf("three");
else if(i==4)printf("four");
else if(i==5)printf("five");
else if(i==6) printf("six");
else if(i==7) printf("seven");
else if(i==8)printf("eight");
else(i>9) printf("even"+"/n"+"odd");
}
return 0;
}
Can i sum up this code into a sorter form ? And why do i get this exeption?
thank you all
Add some brackets "{}".
Code will looks better and will work.
if(expression) {
} elseif(expression) {
} elseif(expression) {
} else {
}
PS. I know it will better. If this text be comment. But I don't have points reputation yet :(
PS2. #Myst if code will have 9. Code don't printf anything.
else clause can't have a condition. So, you either mean just else or else if (i>9).
Besides, C doesn't have + operator that concatenates strings. You can just leave out the + and the C preprocessor will concatenate adjacent string literals (see C11, 5.1.1.2, 6).
else if(i>9) printf("even" "/n" "odd");
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 keep getting the warning that my function has an undefined reference and that doesn't really say much to me or how to fix it. Here are the errors
log_2.c: In function ‘main’: log_2.c:29: warning: implicit
declaration of function ‘logbase2’ /tmp/ccAXAmVb.o: In function
'main': log_2.c:(.text+0x5e): undefined reference to `logbase2'
collect2: ld returned 1 exit status
Heres my code:
int logbasetwo (int number)
{
int test;
for (int i = 0; i< number; i++){
test = 2 ^ i;
int result = i;
}
return result;
}
int main(){
printf("Enter a positive integer: ");
int number = get_int();
int logresult;
if (number > 0){
logresult=logbase2(number);
}
else (number < 0){
printf("Not a positive number. Re-enter: ");
number = get_int();
}
printf("Log base two of number is:%i", logresult);
}
return 0;
}
Well, in your code , both logbase2() and logbasetwo() are used, which are not the same !!!
You have defined a function named logbasetwo(), but you called logbase2().
Change either of them to match other one.
Also, you need to change the logic test = 2 ^ i;. As mentioned in earlier comment by Mr. #Bathsheba, ^ operator is for XOR, not exponentiation.
You need to use pow().
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
I'm trying to compile a programme in c but I keep getting the same two errors. The errors I get are:
error: expected ‘)’ before ‘idSubject’
printf("%d" idSubject);
and the other one:
format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
Here's the code:
#include <stdio.h>
#include <stdlib.h>
void averageMark (idSubjectE) {
typedef enum {FALSE,TRUE} bool;
int i;
float acum;
int idChair;
int idSubject;
int numEst;
float mark;
bool found=FALSE;
scanf("%d", &idChair);
printf ("%d", idChair);
scanf("%d", &idSubject);
while (idSubject!=0) {
scanf("%d", &numEst);
if (idSubject==idSubjectE) {
printf("%d" idSubject);
found=TRUE;
for (i=1; i<numEst*2; i++) {
if (i%2==0){
scanf("%f", &mark);
acum=acum+mark;
}
}
printf("%f", acum/(float)numEst);
}
scanf("%d", &idSubject);
}
}
int main(){
averageMark(12);
}
I've been trying and trying but I can't find the mistake,
change printf("%d" idSubject); to printf("%d", idSubject); notice the ,