Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
January 13th, 2013, 05:33 PM
 sissiv6itleja
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;
}

#2
January 13th, 2013, 05:49 PM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,258
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 22 m 54 sec
Reputation Power: 1827
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.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

#3
January 13th, 2013, 08:25 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,157
Time spent in forums: 1 Month 3 Weeks 2 Days 8 h 41 m 50 sec
Reputation Power: 455
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!

#4
January 15th, 2013, 02:17 PM
 sissiv6itleja
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 :

#5
January 15th, 2013, 02:30 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,157
Time spent in forums: 1 Month 3 Weeks 2 Days 8 h 41 m 50 sec
Reputation Power: 455
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 07:32 PM.

#6
January 15th, 2013, 06:46 PM
 sissiv6itleja
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

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Need code check help

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |