IPB
ЛогинПароль:

> Внимание!

1. Пользуйтесь тегами кода. - [code] ... [/code]
2. Точно указывайте язык, название и версию компилятора (интерпретатора).
3. Название темы должно быть информативным.
В описании темы указываем язык!!!

Наладить общение поможет, если вы подпишитесь по почте на новые темы в этом форуме.

> Программа на С, есть на паскале, желательно ещё и на С
сообщение
Сообщение #1





Группа: Пользователи
Сообщений: 4
Пол: Женский

Репутация: -  0  +


Код

Вначале создан Юнит

Unit Iterate;

interface

Uses crt, Graph;

Var a,i,b,k,Err,x0,y0,x1,y1,m,w,x3,y3,x2,y2:integer;
    x,y,s:extended;

procedure Init_Graph;
function iterative(x:real):real;
function recursive(a,x,b:extended):extended;
procedure gra;

Implementation

procedure Init_Graph;
var GD, GM, EC: Integer;
begin
GD:= Detect;
  InitGraph(GD,GM,'C:\Program Files\Turbo_Pascal\BGI\');
EC:= GraphResult;
  if EC<>GrOK then
   begin
    WriteLn('Error Graphic Initialize: ', GraphErrorMsg(EC));
    Halt(1);
   end;
end;

function iterative(x:real):real;
   var a,b:real;
    begin

a:=x;     s:=0;
     b:=1;

         while abs(a/b)>0.001 do
            begin
              s:=s+a/b;
              a:=a*(-x*x);
              b:=b+2;
            end;
              iterative:=s;

    end;

function recursive(a,x,b:extended):extended;
      begin

         if abs(a/b)>0.01 then

         recursive:=recursive(a*(-x*x),x,b+2)+(a/b)

         else recursive:=0;
     end;

procedure gra;

begin
     x0:=200;
     y0:=250;

m:=150;
w:=150;

SetColor(2);
{coord.line.x}
Line(0,450,639,450);
                  {arrows x}
                  Line(639,450,629,445);
                  Line(639,450,629,455);
{coord.line.y}
Line(200,0,200,479);
                  {arrows y}
                  Line(200,0,205,10);
                  Line(200,0,195,10);

{text.x;text.y}
OutTextXY(210,5,'Y');
OutTextXY(630,435,'X');
OutTextXY(205,455,'0');
OutTextXY(50,455,'-1');
OutTextXY(350,455,'1');
SetLineStyle(3,0,1);
Line(350,450,350,50);
Line(50,455,50,50);

SetColor(2);
SetLineStyle(0,0,0);
Rectangle(380,120,385,125);
OutTextXY(390,120,'Function y=arctan(x)');
SetColor(4);
Rectangle(380,140,385,145);
OutTextXY(390,140,'Iterative');
SetColor(5);
Rectangle(380,160,385,165);
OutTextXY(390,160,'Recursive');
SetColor(2);
OutTextXY(390,180,'for next - press ENTER');


readkey;
x:=-1;

      while x<=1 do

         begin
            y:=arctan(x);
            x1:=Round(x0+x*w);
            y1:=Round(y0-y*m);
            PutPixel(x1,y1,2);
            x:=x+0.001;
         end;


readkey;
x:=-1;
      while x<=1 do

         begin
            x2:=Round(x0+x*w);
            y2:=Round(y0-iterative(x)*m);
            PutPixel(x2,y2,4);
            x:=x+0.001;
          end;
readkey;

x:=-1;

      while x<=1 do

         begin
            x3:=Round(x0+x*w);
            y3:=Round(y0-recursive(x,x,1)*m);
            PutPixel(x3,y3,5);
            x:=x+0.001;
         end;
         readkey;

{end.else.point.}
end;

End.



Затем главная программа


program individualka;

Uses Crt,Graph,Iterate;

Var a,b,i,k,Err,x0,y0,x1,y1,m,w,x2,y2,x3,y3:integer;
    x,y,s:extended;

   Begin
clrscr;
x:=-1;
write('||    X    ||  Iterative  ||   Recursive   ||    Arctg    ||');
writeln('');
while x<=1.1 do

begin
if x>0 then TextColor(Red) else
TextColor(Green);
writeln('||  ',x:3:2,'   ||   ',iterative(x):3:2,'    ||    ',recursive(x,x,1):3:2,'     ||    ', arctan(x):3:2,'   ||');
x:=x+0.1;
end;

Textcolor(Green);
writeln('');
write('press any key for graphics drawing...');
readkey;

Init_Graph;
gra;

readkey;
CloseGraph;
End.





Товарищи, если не тяжело, помогите. Нужно написать эту же программу на С. Желательно, без изменений.
Заранее благодарна.
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 
 
 Ответить  Открыть новую тему 
Ответов(1 - 2)
сообщение
Сообщение #2


Гость






Что-то вот такого типа:
1) файл ITERATE.H:
#ifndef __ITERATE_H__
#define __ITERATE_H__

void init_graph();
float iterative(float);
double recursive(double, double, double);
void gra();

extern int x0, y0, m, w, x1, y1, x2, y2, x3, y3;

#endif

2) файл ITERATE.CPP
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>

#include "ITERATE.H"

/*
Var a,i,b,k,Err,x0,y0,x1,y1,m,w,x3,y3,x2,y2:integer;
x,y,s:extended;
*/

int x0, y0, x1, y1, x2, y2, x3, y3, m, w;

void init_graph() {

int error_code, graph_mode, graph_driver = DETECT;
initgraph(&graph_driver, &graph_mode, "");
if((error_code = graphresult()) != grOk) {
printf("Error Graphic Initialize: %s\n", grapherrormsg(error_code));
getch();
exit(1);
}
}

float iterative(float x) {

// var a,b:real;
float a = x, s = 0;
float b = 1;

while(fabs(a / b) > 0.001) {
s += a / b;
a *= (-x*x);
b += 2;
}
return s;
}

double recursive(double a, double x, double b) {

if(fabs(a / b) > 0.01)
return recursive(a*(-x*x), x, b+2) + (a / b);
else return 0;

}

void gra() {

x0=200; y0=250;
m =150; w =150;

setcolor(GREEN);
// coord.line.x
line(0,450,639,450);

// arrows x
line(639,450,629,445);
line(639,450,629,455);

// coord.line.y
line(200,0,200,479);

// arrows y
line(200,0,205,10);
line(200,0,195,10);

// text.x; text.y
outtextxy(210, 5, "Y");
outtextxy(630,435, "X");
outtextxy(205,455, "0");
outtextxy( 50,455,"-1");
outtextxy(350,455, "1");
setlinestyle(DASHED_LINE, 0, 1);
line(350,450,350,50);
line(50,455,50,50);

setcolor(GREEN);
setlinestyle(SOLID_LINE, 0, 0);
rectangle(380,120,385,125);
outtextxy(390,120,"Function y=arctan(x)");
setcolor(RED);
rectangle(380,140,385,145);
outtextxy(390,140,"Iterative");
setcolor(MAGENTA);
rectangle(380,160,385,165);
outtextxy(390,160,"Recursive");
setcolor(GREEN);
outtextxy(390,180,"for next - press ENTER");

getch();
double x = -1, y;

while(x <= 1) {
y = atan(x);
x1 = (int)(x0 + x*w);
y1 = (int)(y0 - y*m);
putpixel(x1, y1, GREEN);
x += 0.001;
}

getch();
x = -1;
while(x <= 1) {
x2 = (int)(x0+x*w);
y2 = (int)(y0-iterative(x)*m);
putpixel(x2, y2, RED);
x += 0.001;
}
getch();

x = -1;
while(x <= 1) {
x3 = (int)(x0+x*w);
y3 = (int)(y0-recursive(x,x,1)*m);
putpixel(x3, y3, MAGENTA);
x += 0.001;
}
getch();

// end.else.point.
}

3) файл MAIN.CPP
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>

#include "ITERATE.H"
// Uses Crt,Graph,Iterate;

// Var a,b,i,k,Err,x0,y0,x1,y1,m,w,x2,y2,x3,y3:integer;
// x,y,s:extended;
int main() {

clrscr();
double x = -1;

textcolor(WHITE);
cprintf("|| X || Iterative || Recursive || Arctg ||\n\r\n\r");
while(x <= 1.05) {
if(x > 0) textcolor(LIGHTRED);
else textcolor(LIGHTGREEN);

cprintf("|| %+3.2f || %+3.2f || %+3.2f || %+3.2f ||\n\r",
x, iterative(x), recursive(x, x, 1), atan(x)
);
x += 0.1;
}

textcolor(LIGHTGREEN);
cprintf("\n\rpress any key for graphics drawing...");
getch();

init_graph();
gra();
getch();

closegraph();
return 0;
}


Придется открыть проект, и оба CPP файла к этому проекту добавить (С++ не позволяет делать так, как Pascal, чтобы просто откомпилировать модуль, и потом его использовать в программе - нужно добавлять все CPP, или OBJ, но все равно добавлять, файлы)...

Разберешься? (тестировалось на TC++ 3.0)
 К началу страницы 
+ Ответить 
сообщение
Сообщение #3





Группа: Пользователи
Сообщений: 4
Пол: Женский

Репутация: -  0  +


Огромное спасибо. Да, конечно, разберусь) smile.gif

 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 

 Ответить  Открыть новую тему 
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 





- Текстовая версия 29.03.2024 8:28
500Gb HDD, 6Gb RAM, 2 Cores, 7 EUR в месяц — такие хостинги правда бывают
Связь с администрацией: bu_gen в домене octagram.name