SlideShare a Scribd company logo
1 of 9
Download to read offline
//operating system Linux,ubuntu,Mac
#include
#include
#include
#include
/*Sum function implementation*/
int sum(int number1,int number2){
return number1+number2;
}
/*sub function implementation*/
int sub(int number1,int number2){
return number1-number2;
}
/*mul function implementation*/
int mul(int number1,int number2){
return number1*number2;
}
/*divide function implementation*/
float divide(int number1,int number2){
if(number2==0){
printf("We can not divide by 0  ");
return 0.0f;
}
return (float)(number1/number2);
}
char *substring(char *string, int position, int length)
{
char *pointer;
int c;
pointer = malloc(length+1);
if (pointer == NULL)
{
printf("Unable to allocate memory. ");
exit(1);
}
for (c = 0 ; c < length ; c++)
{
*(pointer+c) = *(string+position-1);
string++;
}
*(pointer+c) = '0';
return pointer;
}
/*Main Function start*/
int main(int argc, char *argv[]){
/*Variable declarations*/
int number1,number2;
char *operator,*str1,*str2;
char line[50];
char s[2] = " ";
int errorFlag=0;// checking if user entered more then one operands
while(1){
/*User input*/
printf("Please Enter the command ");
gets(line);
int len=0;
for(int i=0; line[i]!='0'; ++i){len++;}
if(len==0){
return 1;
}
/*Spliting into Tokens*/
operator = strtok(line, " ");
if(strcmp(operator,"bye")==0){
break;
}
/*String to integer --- token1*/
number1=atoi(strtok(NULL, s));
/*Removing ( and ) from String*/
str2=strtok(NULL, s);
char *content;int length=0;
for(int i=0; str2[i]!='0'; ++i){length++;}
if(str2[0]=='('){
content=substring(str2,2,length-1);
char *opr=content;
int n1=atoi(strtok(NULL, s));
int n2=atoi(strtok(NULL, s));
/*If user entered more then two operands then it will return some token otherwise it will
return NULL pointer*/
if(strtok(NULL, s)!=NULL){
printf("You need to enter operator operand1 operand2  ");
errorFlag=1;
}else{
if(strcmp(opr,"sum")==0){
number2=sum(n1,n2);
}else if(strcmp(opr,"sub")==0){
number2=sub(n1,n2);
}else if(strcmp(opr,"mul")==0){
number2=mul(n1,n2);
} else if(strcmp(opr,"div")==0){
number2=divide(n1,n2);
}
}
}else{
number2=atoi(str2);
/*If user entered more then two operands then it will return some token otherwise it will return
NULL pointer*/
if(strtok(NULL, s)!=NULL){
printf("You need to enter operator operand1 operand2  ");
errorFlag=1;
}
}
if(errorFlag!=1){
/*Checking operator by strcmp function*/
if(strcmp(operator,"sum")==0){
printf("Result %d  ",sum(number1,number2));
}else if(strcmp(operator,"sub")==0){
printf("Result %d  ",sub(number1,number2));
}else if(strcmp(operator,"mul")==0){
printf("Result %d  ",mul(number1,number2));
} else if(strcmp(operator,"div")==0){
printf("Result %.2f  ",divide(number1,number2));
}
}
}
return 0;
}
/********************output************************/
gopal@gopal:~/Desktop/chegg$ gcc Calculator.c
Calculator.c: In function ‘main’:
Calculator.c:67:3: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-
declaration]
gets(line);
^
/tmp/ccgPlkE8.o: In function `main':
Calculator.c:(.text+0x154): warning: the `gets' function is dangerous and should not be used.
gopal@gopal:~/Desktop/chegg$ ./a.out
Please Enter the command sum 2 3
Result 5
Please Enter the command mul 5 (mul 7 3)
Result 105
Please Enter the command sum 2 3 4
You need to enter operator operand1 operand2
Please Enter the command mul 5 (mul 7 3 2)
You need to enter operator operand1 operand2
Please Enter the command mul 5 (mul 7 3) 2
You need to enter operator operand1 operand2
Please Enter the command bye
Solution
//operating system Linux,ubuntu,Mac
#include
#include
#include
#include
/*Sum function implementation*/
int sum(int number1,int number2){
return number1+number2;
}
/*sub function implementation*/
int sub(int number1,int number2){
return number1-number2;
}
/*mul function implementation*/
int mul(int number1,int number2){
return number1*number2;
}
/*divide function implementation*/
float divide(int number1,int number2){
if(number2==0){
printf("We can not divide by 0  ");
return 0.0f;
}
return (float)(number1/number2);
}
char *substring(char *string, int position, int length)
{
char *pointer;
int c;
pointer = malloc(length+1);
if (pointer == NULL)
{
printf("Unable to allocate memory. ");
exit(1);
}
for (c = 0 ; c < length ; c++)
{
*(pointer+c) = *(string+position-1);
string++;
}
*(pointer+c) = '0';
return pointer;
}
/*Main Function start*/
int main(int argc, char *argv[]){
/*Variable declarations*/
int number1,number2;
char *operator,*str1,*str2;
char line[50];
char s[2] = " ";
int errorFlag=0;// checking if user entered more then one operands
while(1){
/*User input*/
printf("Please Enter the command ");
gets(line);
int len=0;
for(int i=0; line[i]!='0'; ++i){len++;}
if(len==0){
return 1;
}
/*Spliting into Tokens*/
operator = strtok(line, " ");
if(strcmp(operator,"bye")==0){
break;
}
/*String to integer --- token1*/
number1=atoi(strtok(NULL, s));
/*Removing ( and ) from String*/
str2=strtok(NULL, s);
char *content;int length=0;
for(int i=0; str2[i]!='0'; ++i){length++;}
if(str2[0]=='('){
content=substring(str2,2,length-1);
char *opr=content;
int n1=atoi(strtok(NULL, s));
int n2=atoi(strtok(NULL, s));
/*If user entered more then two operands then it will return some token otherwise it will
return NULL pointer*/
if(strtok(NULL, s)!=NULL){
printf("You need to enter operator operand1 operand2  ");
errorFlag=1;
}else{
if(strcmp(opr,"sum")==0){
number2=sum(n1,n2);
}else if(strcmp(opr,"sub")==0){
number2=sub(n1,n2);
}else if(strcmp(opr,"mul")==0){
number2=mul(n1,n2);
} else if(strcmp(opr,"div")==0){
number2=divide(n1,n2);
}
}
}else{
number2=atoi(str2);
/*If user entered more then two operands then it will return some token otherwise it will return
NULL pointer*/
if(strtok(NULL, s)!=NULL){
printf("You need to enter operator operand1 operand2  ");
errorFlag=1;
}
}
if(errorFlag!=1){
/*Checking operator by strcmp function*/
if(strcmp(operator,"sum")==0){
printf("Result %d  ",sum(number1,number2));
}else if(strcmp(operator,"sub")==0){
printf("Result %d  ",sub(number1,number2));
}else if(strcmp(operator,"mul")==0){
printf("Result %d  ",mul(number1,number2));
} else if(strcmp(operator,"div")==0){
printf("Result %.2f  ",divide(number1,number2));
}
}
}
return 0;
}
/********************output************************/
gopal@gopal:~/Desktop/chegg$ gcc Calculator.c
Calculator.c: In function ‘main’:
Calculator.c:67:3: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-
declaration]
gets(line);
^
/tmp/ccgPlkE8.o: In function `main':
Calculator.c:(.text+0x154): warning: the `gets' function is dangerous and should not be used.
gopal@gopal:~/Desktop/chegg$ ./a.out
Please Enter the command sum 2 3
Result 5
Please Enter the command mul 5 (mul 7 3)
Result 105
Please Enter the command sum 2 3 4
You need to enter operator operand1 operand2
Please Enter the command mul 5 (mul 7 3 2)
You need to enter operator operand1 operand2
Please Enter the command mul 5 (mul 7 3) 2
You need to enter operator operand1 operand2
Please Enter the command bye

More Related Content

Similar to operating system Linux,ubuntu,Mac#include stdio.h #include .pdf

fraction_math.c for Project 5 Program Design fraction.pdf
fraction_math.c for Project 5  Program Design  fraction.pdffraction_math.c for Project 5  Program Design  fraction.pdf
fraction_math.c for Project 5 Program Design fraction.pdfanjanadistribution
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2zindadili
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
 
C for Java programmers (part 3)
C for Java programmers (part 3)C for Java programmers (part 3)
C for Java programmers (part 3)Dmitry Zinoviev
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docxtarifarmarie
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfaioils
 
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdfimplement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdfforladies
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematicakrasul
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within MathematicaShoaib Burq
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfclarityvision
 

Similar to operating system Linux,ubuntu,Mac#include stdio.h #include .pdf (20)

fraction_math.c for Project 5 Program Design fraction.pdf
fraction_math.c for Project 5  Program Design  fraction.pdffraction_math.c for Project 5  Program Design  fraction.pdf
fraction_math.c for Project 5 Program Design fraction.pdf
 
Unit 4
Unit 4Unit 4
Unit 4
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
Templates
TemplatesTemplates
Templates
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
C for Java programmers (part 3)
C for Java programmers (part 3)C for Java programmers (part 3)
C for Java programmers (part 3)
 
Lecture5
Lecture5Lecture5
Lecture5
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
 
Microkernel Development
Microkernel DevelopmentMicrokernel Development
Microkernel Development
 
week-15x
week-15xweek-15x
week-15x
 
week-16x
week-16xweek-16x
week-16x
 
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdfimplement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematica
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within Mathematica
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
 
c programming
c programmingc programming
c programming
 

More from aquazac

Answer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdfAnswer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdfaquazac
 
Ans. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdfAns. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdfaquazac
 
additional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdfadditional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdfaquazac
 
According to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdfAccording to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdfaquazac
 
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdfa) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdfaquazac
 
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdfaquazac
 
A person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdfA person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdfaquazac
 
Well.. 1) Ionic bonds are almost always metal to .pdf
                     Well.. 1) Ionic bonds are almost always metal to .pdf                     Well.. 1) Ionic bonds are almost always metal to .pdf
Well.. 1) Ionic bonds are almost always metal to .pdfaquazac
 
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdfaquazac
 
clear clc close all Use polyfit to solve for the phase l.pdf
 clear clc close all Use polyfit to solve for the phase l.pdf clear clc close all Use polyfit to solve for the phase l.pdf
clear clc close all Use polyfit to solve for the phase l.pdfaquazac
 
The oxygen appears in both step reactions. But, i.pdf
                     The oxygen appears in both step reactions. But, i.pdf                     The oxygen appears in both step reactions. But, i.pdf
The oxygen appears in both step reactions. But, i.pdfaquazac
 
PART A The element Si belongs to IVA group. Therefore, four electro.pdf
  PART A The element Si belongs to IVA group. Therefore, four electro.pdf  PART A The element Si belongs to IVA group. Therefore, four electro.pdf
PART A The element Si belongs to IVA group. Therefore, four electro.pdfaquazac
 
The two contributions to the cohesive energy of t.pdf
                     The two contributions to the cohesive energy of t.pdf                     The two contributions to the cohesive energy of t.pdf
The two contributions to the cohesive energy of t.pdfaquazac
 
If you are talking about an extraction design, th.pdf
                     If you are talking about an extraction design, th.pdf                     If you are talking about an extraction design, th.pdf
If you are talking about an extraction design, th.pdfaquazac
 
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdfYes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdfaquazac
 
When something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdfWhen something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdfaquazac
 
We need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdfWe need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdfaquazac
 
What is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdfWhat is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdfaquazac
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfaquazac
 
This electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdfThis electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdfaquazac
 

More from aquazac (20)

Answer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdfAnswer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdf
 
Ans. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdfAns. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdf
 
additional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdfadditional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdf
 
According to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdfAccording to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdf
 
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdfa) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
 
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
 
A person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdfA person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdf
 
Well.. 1) Ionic bonds are almost always metal to .pdf
                     Well.. 1) Ionic bonds are almost always metal to .pdf                     Well.. 1) Ionic bonds are almost always metal to .pdf
Well.. 1) Ionic bonds are almost always metal to .pdf
 
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
 
clear clc close all Use polyfit to solve for the phase l.pdf
 clear clc close all Use polyfit to solve for the phase l.pdf clear clc close all Use polyfit to solve for the phase l.pdf
clear clc close all Use polyfit to solve for the phase l.pdf
 
The oxygen appears in both step reactions. But, i.pdf
                     The oxygen appears in both step reactions. But, i.pdf                     The oxygen appears in both step reactions. But, i.pdf
The oxygen appears in both step reactions. But, i.pdf
 
PART A The element Si belongs to IVA group. Therefore, four electro.pdf
  PART A The element Si belongs to IVA group. Therefore, four electro.pdf  PART A The element Si belongs to IVA group. Therefore, four electro.pdf
PART A The element Si belongs to IVA group. Therefore, four electro.pdf
 
The two contributions to the cohesive energy of t.pdf
                     The two contributions to the cohesive energy of t.pdf                     The two contributions to the cohesive energy of t.pdf
The two contributions to the cohesive energy of t.pdf
 
If you are talking about an extraction design, th.pdf
                     If you are talking about an extraction design, th.pdf                     If you are talking about an extraction design, th.pdf
If you are talking about an extraction design, th.pdf
 
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdfYes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
 
When something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdfWhen something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdf
 
We need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdfWe need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdf
 
What is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdfWhat is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdf
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
 
This electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdfThis electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdf
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

operating system Linux,ubuntu,Mac#include stdio.h #include .pdf

  • 1. //operating system Linux,ubuntu,Mac #include #include #include #include /*Sum function implementation*/ int sum(int number1,int number2){ return number1+number2; } /*sub function implementation*/ int sub(int number1,int number2){ return number1-number2; } /*mul function implementation*/ int mul(int number1,int number2){ return number1*number2; } /*divide function implementation*/ float divide(int number1,int number2){ if(number2==0){ printf("We can not divide by 0 "); return 0.0f; } return (float)(number1/number2); } char *substring(char *string, int position, int length) { char *pointer; int c; pointer = malloc(length+1); if (pointer == NULL) {
  • 2. printf("Unable to allocate memory. "); exit(1); } for (c = 0 ; c < length ; c++) { *(pointer+c) = *(string+position-1); string++; } *(pointer+c) = '0'; return pointer; } /*Main Function start*/ int main(int argc, char *argv[]){ /*Variable declarations*/ int number1,number2; char *operator,*str1,*str2; char line[50]; char s[2] = " "; int errorFlag=0;// checking if user entered more then one operands while(1){ /*User input*/ printf("Please Enter the command "); gets(line); int len=0; for(int i=0; line[i]!='0'; ++i){len++;} if(len==0){ return 1; } /*Spliting into Tokens*/ operator = strtok(line, " ");
  • 3. if(strcmp(operator,"bye")==0){ break; } /*String to integer --- token1*/ number1=atoi(strtok(NULL, s)); /*Removing ( and ) from String*/ str2=strtok(NULL, s); char *content;int length=0; for(int i=0; str2[i]!='0'; ++i){length++;} if(str2[0]=='('){ content=substring(str2,2,length-1); char *opr=content; int n1=atoi(strtok(NULL, s)); int n2=atoi(strtok(NULL, s)); /*If user entered more then two operands then it will return some token otherwise it will return NULL pointer*/ if(strtok(NULL, s)!=NULL){ printf("You need to enter operator operand1 operand2 "); errorFlag=1; }else{ if(strcmp(opr,"sum")==0){ number2=sum(n1,n2); }else if(strcmp(opr,"sub")==0){ number2=sub(n1,n2); }else if(strcmp(opr,"mul")==0){ number2=mul(n1,n2); } else if(strcmp(opr,"div")==0){ number2=divide(n1,n2); } } }else{
  • 4. number2=atoi(str2); /*If user entered more then two operands then it will return some token otherwise it will return NULL pointer*/ if(strtok(NULL, s)!=NULL){ printf("You need to enter operator operand1 operand2 "); errorFlag=1; } } if(errorFlag!=1){ /*Checking operator by strcmp function*/ if(strcmp(operator,"sum")==0){ printf("Result %d ",sum(number1,number2)); }else if(strcmp(operator,"sub")==0){ printf("Result %d ",sub(number1,number2)); }else if(strcmp(operator,"mul")==0){ printf("Result %d ",mul(number1,number2)); } else if(strcmp(operator,"div")==0){ printf("Result %.2f ",divide(number1,number2)); } } } return 0; } /********************output************************/ gopal@gopal:~/Desktop/chegg$ gcc Calculator.c Calculator.c: In function ‘main’: Calculator.c:67:3: warning: implicit declaration of function ‘gets’ [-Wimplicit-function- declaration] gets(line); ^ /tmp/ccgPlkE8.o: In function `main':
  • 5. Calculator.c:(.text+0x154): warning: the `gets' function is dangerous and should not be used. gopal@gopal:~/Desktop/chegg$ ./a.out Please Enter the command sum 2 3 Result 5 Please Enter the command mul 5 (mul 7 3) Result 105 Please Enter the command sum 2 3 4 You need to enter operator operand1 operand2 Please Enter the command mul 5 (mul 7 3 2) You need to enter operator operand1 operand2 Please Enter the command mul 5 (mul 7 3) 2 You need to enter operator operand1 operand2 Please Enter the command bye Solution //operating system Linux,ubuntu,Mac #include #include #include #include /*Sum function implementation*/ int sum(int number1,int number2){ return number1+number2; } /*sub function implementation*/ int sub(int number1,int number2){ return number1-number2; } /*mul function implementation*/ int mul(int number1,int number2){ return number1*number2; } /*divide function implementation*/ float divide(int number1,int number2){ if(number2==0){
  • 6. printf("We can not divide by 0 "); return 0.0f; } return (float)(number1/number2); } char *substring(char *string, int position, int length) { char *pointer; int c; pointer = malloc(length+1); if (pointer == NULL) { printf("Unable to allocate memory. "); exit(1); } for (c = 0 ; c < length ; c++) { *(pointer+c) = *(string+position-1); string++; } *(pointer+c) = '0'; return pointer; } /*Main Function start*/ int main(int argc, char *argv[]){ /*Variable declarations*/ int number1,number2; char *operator,*str1,*str2; char line[50];
  • 7. char s[2] = " "; int errorFlag=0;// checking if user entered more then one operands while(1){ /*User input*/ printf("Please Enter the command "); gets(line); int len=0; for(int i=0; line[i]!='0'; ++i){len++;} if(len==0){ return 1; } /*Spliting into Tokens*/ operator = strtok(line, " "); if(strcmp(operator,"bye")==0){ break; } /*String to integer --- token1*/ number1=atoi(strtok(NULL, s)); /*Removing ( and ) from String*/ str2=strtok(NULL, s); char *content;int length=0; for(int i=0; str2[i]!='0'; ++i){length++;} if(str2[0]=='('){ content=substring(str2,2,length-1); char *opr=content; int n1=atoi(strtok(NULL, s)); int n2=atoi(strtok(NULL, s)); /*If user entered more then two operands then it will return some token otherwise it will return NULL pointer*/ if(strtok(NULL, s)!=NULL){
  • 8. printf("You need to enter operator operand1 operand2 "); errorFlag=1; }else{ if(strcmp(opr,"sum")==0){ number2=sum(n1,n2); }else if(strcmp(opr,"sub")==0){ number2=sub(n1,n2); }else if(strcmp(opr,"mul")==0){ number2=mul(n1,n2); } else if(strcmp(opr,"div")==0){ number2=divide(n1,n2); } } }else{ number2=atoi(str2); /*If user entered more then two operands then it will return some token otherwise it will return NULL pointer*/ if(strtok(NULL, s)!=NULL){ printf("You need to enter operator operand1 operand2 "); errorFlag=1; } } if(errorFlag!=1){ /*Checking operator by strcmp function*/ if(strcmp(operator,"sum")==0){ printf("Result %d ",sum(number1,number2)); }else if(strcmp(operator,"sub")==0){ printf("Result %d ",sub(number1,number2)); }else if(strcmp(operator,"mul")==0){ printf("Result %d ",mul(number1,number2)); } else if(strcmp(operator,"div")==0){ printf("Result %.2f ",divide(number1,number2)); }
  • 9. } } return 0; } /********************output************************/ gopal@gopal:~/Desktop/chegg$ gcc Calculator.c Calculator.c: In function ‘main’: Calculator.c:67:3: warning: implicit declaration of function ‘gets’ [-Wimplicit-function- declaration] gets(line); ^ /tmp/ccgPlkE8.o: In function `main': Calculator.c:(.text+0x154): warning: the `gets' function is dangerous and should not be used. gopal@gopal:~/Desktop/chegg$ ./a.out Please Enter the command sum 2 3 Result 5 Please Enter the command mul 5 (mul 7 3) Result 105 Please Enter the command sum 2 3 4 You need to enter operator operand1 operand2 Please Enter the command mul 5 (mul 7 3 2) You need to enter operator operand1 operand2 Please Enter the command mul 5 (mul 7 3) 2 You need to enter operator operand1 operand2 Please Enter the command bye