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

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 13th, 2013, 04:33 PM
sissiv6itleja sissiv6itleja is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 sissiv6itleja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}

Reply With Quote
  #2  
Old January 13th, 2013, 04:49 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 19 h 25 m 12 sec
Reputation Power: 1774
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

Reply With Quote
  #3  
Old January 13th, 2013, 07:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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!

Reply With Quote
  #4  
Old January 15th, 2013, 01:17 PM
sissiv6itleja sissiv6itleja is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 sissiv6itleja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 :

Reply With Quote
  #5  
Old January 15th, 2013, 01:30 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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.

Reply With Quote
  #6  
Old January 15th, 2013, 05:46 PM
sissiv6itleja sissiv6itleja is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 sissiv6itleja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC 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 
Rate This Thread:


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap