The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Need code check help
Discuss Need code check help in the C Programming forum on Dev Shed. Need code check help C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 13th, 2013, 04:33 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 44 m 41 sec
Reputation Power: 0
|
|
|
Need code check help
The task is - Argument initial value A, step H and the number of steps N. Calculate the value of the function in A, A + H, A + 2*H, … , A + N*H.
and function itself is prntscr.com/p381j
(new members are not allowed to add url or pics)
I have write my code into example task code and theree are some errors. Dont beat me please for this ugly code and lets learn together
Code:
#include <stdio.h>
#include <math.h>
void sisestamine (int A, int H, int N)
{
printf("Sisesta funktsiooni argumendi Algväärtus A\n");
scanf("%d", A);
printf("Sisesta sammu v22rtus H\n");
scanf("%d", H);
printf("Sisesta sammude arv N\n");
scanf("%d", N);
}
void arvutamine (int A, int H, int N, int x, float y)
{
int i=0;
int x=A;
do
{
y[i] = ((pow(sin.2)(x[i]+5))+(cos(x[i])))/(x[i]+(pow(2,72.(x[i]+3))));
A=A*H
i++;
}
while (i<N);
}
void v2ljastus (int x, float y)
{
int i;
printf("X | Y\n");
for(i=0;i<=N;i++)
{
printf("%d | %f\n", x[i], y[i]);
}
}
int main(void)
{
int i;
int x;
float y;
int A, H, N;
sisestamine (&A,&H,&N);
arvutamine (A,H,N,x,y);
v2ljastus (x,y);
printf("Vajuta enter v2ljumiseks!\n");
getchar();
return 0;
}
|

January 13th, 2013, 04:49 PM
|
 |
Contributed User
|
|
|
|
First, you need to learn how to indent code.
As well as making it easier for others to help you, it will save you from making many simple mistakes.
Code:
#include <stdio.h>
#include <math.h>
void sisestamine(int A, int H, int N)
{
printf("Sisesta funktsiooni argumendi Algväärtus A\n");
scanf("%d", A);
printf("Sisesta sammu v22rtus H\n");
scanf("%d", H);
printf("Sisesta sammude arv N\n");
scanf("%d", N);
}
void arvutamine(int A, int H, int N, int x, float y)
{
int i = 0;
int x = A;
do {
y[i] = ((pow(sin .2) (x[i] + 5)) + (cos(x[i]))) / (x[i] + (pow(2, 72.(x[i] + 3))));
A = A * H i++;
}
while (i < N);
}
void v2ljastus(int x, float y)
{
int i;
printf("X | Y\n");
for (i = 0; i <= N; i++) {
printf("%d | %f\n", x[i], y[i]);
}
}
int main(void)
{
int i;
int x;
float y;
int A, H, N;
sisestamine(&A, &H, &N);
arvutamine(A, H, N, x, y);
v2ljastus(x, y);
printf("Vajuta enter v2ljumiseks!\n");
getchar();
return 0;
}
The next thing to do is get a decent compiler.
Code:
$ gcc -Wall -Wextra foo.c
foo.c: In function ‘sisestamine’:
foo.c:7:3: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]
foo.c:9:3: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]
foo.c:11:3: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat]
foo.c: In function ‘arvutamine’:
foo.c:18:7: error: ‘x’ redeclared as different kind of symbol
foo.c:15:42: note: previous definition of ‘x’ was here
foo.c:20:6: error: subscripted value is neither array nor pointer nor vector
foo.c:20:22: error: expected ‘)’ before numeric constant
foo.c:20:22: error: incompatible type for argument 1 of ‘pow’
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:154:1: note: expected ‘double’ but argument is of type ‘__attribute__((const)) double (*)(double)’
foo.c:20:22: error: too few arguments to function ‘pow’
foo.c:20:28: error: subscripted value is neither array nor pointer nor vector
foo.c:20:46: error: subscripted value is neither array nor pointer nor vector
foo.c:20:57: error: subscripted value is neither array nor pointer nor vector
foo.c:20:76: error: subscripted value is neither array nor pointer nor vector
foo.c:20:74: error: called object ‘7.2e+1’ is not a function
foo.c:21:15: error: expected ‘;’ before ‘i’
foo.c:18:7: warning: variable ‘x’ set but not used [-Wunused-but-set-variable]
foo.c:15:51: warning: parameter ‘y’ set but not used [-Wunused-but-set-parameter]
foo.c: In function ‘v2ljastus’:
foo.c:30:20: error: ‘N’ undeclared (first use in this function)
foo.c:30:20: note: each undeclared identifier is reported only once for each function it appears in
foo.c:31:30: error: subscripted value is neither array nor pointer nor vector
foo.c:31:36: error: subscripted value is neither array nor pointer nor vector
foo.c:26:20: warning: parameter ‘x’ set but not used [-Wunused-but-set-parameter]
foo.c:26:29: warning: parameter ‘y’ set but not used [-Wunused-but-set-parameter]
foo.c: In function ‘main’:
foo.c:41:3: warning: passing argument 1 of ‘sisestamine’ makes integer from pointer without a cast [enabled by default]
foo.c:4:6: note: expected ‘int’ but argument is of type ‘int *’
foo.c:41:3: warning: passing argument 2 of ‘sisestamine’ makes integer from pointer without a cast [enabled by default]
foo.c:4:6: note: expected ‘int’ but argument is of type ‘int *’
foo.c:41:3: warning: passing argument 3 of ‘sisestamine’ makes integer from pointer without a cast [enabled by default]
foo.c:4:6: note: expected ‘int’ but argument is of type ‘int *’
foo.c:37:7: warning: unused variable ‘i’ [-Wunused-variable]
One of the really neat things about gcc is that it can tell you when you mess up printf/scanf calls (and you have many of these).
The first problem you have is that sisestamine() is just not returning results back to main.
|

January 13th, 2013, 07:25 PM
|
 |
Contributing User
|
|
|
|
If you write this in TeX format or in a way that wolfram alpha would understand I'll help you write it so that c might parse it.
y[i] = ((pow(sin .2) (x[i] + 5)) + (cos(x[i]))) / (x[i] + (pow(2, 72.(x[i] + 3))));
Difficult because x is declared twice but never as an array.
__________________
[code] Code tags[/code] are essential for python code!
|

January 15th, 2013, 01:17 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 44 m 41 sec
Reputation Power: 0
|
|
Sorry but i have on 16.01 one more examination, after this i can again continue with the code but the function looks like this : 
|

January 15th, 2013, 01:30 PM
|
 |
Contributing User
|
|
|
|
Code:
X = x[i];
y[i] = (pow(sin(X+5),2) + cos(X)) / (X + exp(X+3));
(of course you'll need to declare X)
Last edited by b49P23TIvg : January 15th, 2013 at 06:32 PM.
|

January 15th, 2013, 05:46 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 44 m 41 sec
Reputation Power: 0
|
|
impossible that its so easy  , but i will check tomorrow after examination. Thanks a lot
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|