Home › Forums › C Programming › calculator programme
- This topic has 2 replies, 2 voices, and was last updated 16 years, 8 months ago by yeswanth.
Viewing 2 reply threads
- AuthorPosts
- November 1, 2007 at 8:53 am #2022mrwalesParticipant
can any body get me calculator program in C-lang??Is it possible
- March 14, 2008 at 9:08 pm #3262yeswanthParticipant1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#include<conio.h><br />#include<mouse.h><br />#include<graphics.h><br />#include<string.h><br />#include<stdlib.h><br />#include<winoop.h><br />void main()<br />{<br />int gd=0,gm,i,j,answer,flag=0,k;<br />char prev='1',current,*ch;<br />char *nums[]={" 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "," 0 "};<br />char *num[]={"1","2","3","4","5","6","7","8","9","0"};<br />initgraph(&gd,&gm,"");<br />button b[10],add,sub,exit,equal,mul,div,ac;<br />textbox t;<br />initmouse();<br />showmouse();<br />t.make(150,50,160);<br />for(i=0,j=100;i<10;i++,j+=40)<br />b.make(j,100,nums);<br />add.make(100,150," + ");<br />sub.make(140,150," - ");<br />equal.make(260,150," = ");<br />mul.make(180,150," * ");<br />div.make(220,150," / ");<br />exit.make(350,400," EXIT ");<br />ac.make(300,150," AC ");<br />j=0;<br />while(1)<br />{<br />setcolor(WHITE);<br />while(!flag)//This while terminates when user is finished inputting a number<br />//i.e. when he presses '+', '-', '*', '/'<br />{<br />for(i=0;i<10;i++)<br />{<br />if(b.click())<br />{<br />t.append(num),j++,k=1;//display the number in textbox<br />break;<br />}<br />}<br />if(j==1&&k==1)<br />t.write(""),t.append(num);<br />if(add.click())<br />current='+',flag=1;<br />else if(sub.click())<br />current='-',flag=1;<br />else if(equal.click())<br />current='=',flag=1;<br />else if(mul.click())<br />current='*',flag=1;<br />else if(div.click())<br />current='/',flag=1;<br />else if(exit.click())<br />flag=2;// flag==2 indicates user wants to exit.<br />else if(ac.click())<br />{<br />prev='1';<br />t.write("");<br />}<br />k=0;<br />}//End of second while loop<br />//Now Calculate the result.<br />if(flag==2)<br />break;//flagg==2, go out of the main loop to exit.<br />if(prev=='1')<br />answer=atoi(t.text);<br />else if(prev=='+')<br />answer+=atoi(t.text);<br />else if(prev=='-')<br />answer-=atoi(t.text);<br />else if(prev=='*')<br />answer*=atoi(t.text);<br />else if(prev=='/'&&(atoi(t.text))==0)<br />msgbox("Cannot divide by zero"),prev='1',t.write("");<br />else if(prev=='/')<br />answer/=atoi(t.text);<br />flag=0,j=0;<br />prev=current;<br />itoa(answer,ch,10);<br />t.write(ch);<br />}<br />closegraph();<br />}<br />
- March 14, 2008 at 9:10 pm #3263yeswanthParticipant1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374<br />#include <stdio.h><br />#include <conio.h><br />#include <math.h><br />main()<br />{<br />int a,b,sum,diff,prdct,ch;<br />double sr;<br />long sq,cube;<br />float c,d,ratio;<br />do<br />{<br />clrscr();<br />printf("t*****Ruel Pagayon Copyright--2007--04--10--*****");<br />printf("nnntt*****Simple Calculator*****nn");<br />printf("tt**Operations**n");<br />printf("ttt*(1)Additionn");<br />printf("ttt*(2)Subtractionn");<br />printf("ttt*(3)Multiplicationn");<br />printf("ttt*(4)Divisionn");<br />printf("ttt*(5)Squaren");<br />printf("ttt*(6)Cuben");<br />printf("ttt*(7)SquareRootn");<br />printf("nEnter the number of your choice: ");<br />scanf("%d", &ch);<br />switch(ch)<br />{<br />case 1:<br />printf("nttEnter two numbers: ");<br />scanf("%d %d", &a,&b);<br />sum = a + b;<br />printf("nnttThe Sum is : %d", sum);<br />break;<br />case 2:<br />printf("nttEnter two numbers: ");<br />scanf("%d %d", &a,&b);<br />diff = a - b;<br />printf("nnttThe Difference is : %d", diff);<br />break;<br />case 3:<br />printf("nttEnter two numbers: ");<br />scanf("%d %d", &a,&b);<br />prdct = a * b;<br />printf("nnttThe Product is : %d", prdct);<br />break;<br />case 4:<br />printf("nttEnter two numbers: ");<br />scanf("%f %f", &c,&d);<br />ratio = c / d;<br />printf("nnttThe Quotient is : %f", ratio);<br />break;<br />case 5:<br />printf("nttEnter a number: ");<br />scanf("%d", &a);<br />sq = a * a;<br />printf("nnttThe Square of %d is : %d", a,sq);<br />break;<br />case 6:<br />printf("nttEnter a number: ");<br />scanf("%d", &a);<br />cube = a * a * a;<br />printf("nnttThe Cube of %d is : %d", a,cube);<br />break;<br />case 7:<br />printf("nttEnter a number: ");<br />scanf("%d", &a);<br />sr = sqrt(a);<br />printf("nnttThe SquareRoot of %d is : %f", a,sr);<br />break;<br />}<br />printf("nnnnntttPress 'x' to quit, any other key to continuen");<br />}<br />while (getch() != 'x');<br />}
- AuthorPosts
Viewing 2 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.