Commit 7ecbb37c by viakul

Upload New File

parent 9609658c
Showing with 119 additions and 0 deletions
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int findA(char* equation);
int findB(char* equation);
int findC(char* equation);
int findDiscriminant(int B, int C);
int main()
{
char string[100];
int a;
int b;
int c;
scanf("%s", string);
a= findA(string);
printf("A value %d\n", a);
b= findB(string);
printf("B value %d\n", b);
c= findC(string);
printf("C value %d", c);
return 0;
}
int findA(char* equation){
int i=0;
char A[100]={""};
while(1){
if (((equation[i]>47)&&(equation[i]<58))||(equation[i]=='x')){
if (equation[i]=='x'){
break;
}
else
{
strcat(A, &equation[i]);
i++;
}
A[i]='\0';
return atoi(A);
}else{
printf("you have a mistake in user input. ");
break;
}
}
}
int findB(char* equation){
int i=0;
char B[100]={""};
while(1){
if (equation[i]=='x'){
break;
}
i++;
}
while(1){
if (equation[i]=='+'){
break;
}else if(equation[i]=='-')
{
strncat(B, &equation[i], 1);
break;
}
i++;
}
i++;
while(1){
if (equation[i]=='x'){
break;
}
else
{
strncat(B, &equation[i], 1);
i++;
}
B[i]='\0';
}
return atoi(B);
}
int findC(char* equation){
int i=0;
char C[100]={""};
int m=0;
while(1){
if (equation[i]=='x'){
m++;
}
if (m==2){
break;
}
i++;
}
i=i+1;
strcat(C, &equation[i]);
C[i]='\0';
return atoi(C);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment