program calklin;
uses
crt;
var
a, b, x: real;
begin
textcolor(red);
gotoxy(10, 5);
write('Вас приветствует калькулятор решать линейные уравнения');
gotoxy(10, 6);
write('Введите а=');
readln(a);
gotoxy(10, 7);
write('Введите b=');
readln(b);
gotoxy(10, 8);
if a = 0
then
begin
gotoxy(10, 9);
textcolor(red);
writeln('Нет корней')
end
else
begin
if a <> 0
then
begin
gotoxy(10, 10);
textcolor(red);
x := (-b / a);
writeln('Уравнение имеет корень и он равен: x =', x, '');
end;
end;
end.
package testStudentCode;
//import java.util.Arrays;
import java.util.Scanner;
public class TestStudentCode {
public static void main(String[] args) {
/* This reads the input provided by user
* using keyboard
*/
Scanner scan = new Scanner(System.in);
System.out.print("a = ?");
// This method reads the number provided using keyboard
double a = scan.nextDouble();
System.out.print("b = ?");
double b = scan.nextDouble();
// Closing Scanner after the use
scan.close();
System.out.println(a + "x + (" + b + ") = 0");
if (a == 0) {
System.out.println("a = 0");
} else {
double x = - b / a;
System.out.println("x = " + x);
}
}
}
Объяснение:
как то так
#include <iostream>
#include <string>
using namespace std;
int main()
{
string S,P;
char c[10000] = "";
int C,z;
double R = 1;
getline(cin, S);
S+=' ';
for(int i = 0; i<S.length(); i++)
{
if(S[i] != ' '){
if(S[i] == '-'){z = -1; i++;}
else z = 1;
C = 0;
while((S[i] >='0')&&(S[i] <= '9'))
{
C = C*10 + (S[i] - '0');
i++;
}
C = C*z;
R*=C;
itoa(C,c,10);
if (z == -1)
{
P+='(';
P+=c;
P+=')';
}
else P+=c;
P+="*";
}
}
P[P.length()-1] = '=';
int d,s;
P+=ecvt(R,4,&d,&s);
S = P;
cout << S << "\n";
system("Pause");
return 0;
}