Програмка С# - C#
Формулировка задачи:
У меня есть програма на С помогите перевести принтэфи и сделать коментарии к ней.Зарание благодарен.
#include<stdio.h> #include<conio.h> #include<math.h> void main(){ int xmin,xmax,m,n; float x,y,h,a,b,c; printf("type in limits for x"); scanf("%d%d",&m,&n); printf("type in a speed you want x to gain its value\n"); scanf("%f",&h); if(m<n){ xmin=m; xmax=n; } printf("now define a value 'a' 'b' 'c'\n if a<0 and c doesn't equal to 0 then y=ax^2+bx+c=0\nand when a is bigger than 0 and c=0 then\n y=-a/(x-c) everything else y=a(x+c)\n"); printf("a="); scanf("%f",&a); printf("b="); scanf("%f",&b); printf("c="); scanf("%f",&c); if(int(a)!=0 & (int(b)!=0|int(c)!=0)){ a=floor(a); b=floor(b); c=floor(c); } printf("%s%10s\n","x","y"); for(x=xmin;x<=xmax;x+=h){ if(a<0 && c!=0) y=a*(x*x)+b*x+c; else if(a>0 && c==0) y=-a/x; else y=a*(x+c); printf("%.2f%14.2f\n",x,y); } getch(); }
Решение задачи: «Програмка С#»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace test { class Program { static void Main(string[] args) { int n, m; int xmin = 0; int xmax = 0; double y, h, a, b, c; Console.WriteLine("type in limits for x"); n =Convert.ToInt32(Console.ReadLine()); m = Convert.ToInt32(Console.ReadLine()); switch (m < n) { case true: xmin = m; xmax = n; break; case false: xmin = n; xmax = m; break; } Console.WriteLine("type in a speed you want x to gain its value"); h = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("now define a value 'a' 'b' 'c'\n if a<0 and c doesn't equal to 0 then y=ax^2+bx+c=0\nand when a is bigger than 0 and c=0 then\n y=-a/(x-c) everything else y=a(x+c)\n"); Console.WriteLine("a="); a = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("b="); b = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("c="); c = Convert.ToDouble(Console.ReadLine()); if ((a != 0) & (b != 0 | c != 0)) { a = Math.Floor(a); b = Math.Floor(b); c = Math.Floor(c); } for (double i = xmin; i <=xmax; i += h) { if (a < 0 && c != 0) { y = a * (i * i) + b * i + c; } else if (a > 0 && c == 0) { y = -a / i; } else y = a * (i + c); Console.WriteLine("x={0},y={1}", i, y); } Console.ReadKey(); } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д