+ 3
I am stuck here please help me
https://code.sololearn.com/c4Ki0hR3B2xX/?ref=app Here I am creating an example of c function to find perimeter and area please help me😞😞😞
5 Respuestas
+ 3
You are having 1 parameter in function call but 2 parameters in function definition, also the parameters are separated by comma not semicolon. It should look like 'int square(int a, int b)'
Also you can return only 1 variable either peri or area, if you want to return both either use pointer or return them in array having 2 elements as area and peri or make separate functions for calculating area and perimeter.
Link to function lesson in C for basics https://www.sololearn.com/learn/C/2929/
+ 1
Bro you can't have 2 return statements in the same function
+ 1
Then also it is not working
+ 1
//You have to make two seperate
//functions:
#include <stdio.h>
int area(int a){
int area = a*a;
return area;
}
int peri(int a){
int peri = 4*a;
return peri;
}
int main() {
int k;
scanf("%d",&k);
printf ("Your answer is:\n Area: %d Peri: %d",area(k),peri(k));
return 0;
}
0
#include <stdio.h>
int area,peri;
int square(int a){
peri = 4*a;
area = a*a;
return area*peri;
}
int main() {
int k;
scanf("%d",&k);
k=square(k);
printf ("area=%d peri=%d k=%d",area,peri,k);
return 0;
}
//use this code