tag:blogger.com,1999:blog-24237318136686746592024-03-13T20:26:31.815-07:00C सीखिए | Learn CPawan Mallhttp://www.blogger.com/profile/13987592121022726798noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-2423731813668674659.post-80046906113389925762011-07-15T14:26:00.001-07:002011-07-15T14:26:54.098-07:00A program for custom function : calculator<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on">See below code i have created a calculator with the use of my own custom functions.<br />
<br />
<blockquote>Here you can learn : how to create custom functions in C?</blockquote></div><div dir="ltr" style="text-align: left;" trbidi="on"><br />
</div><div dir="ltr" style="text-align: left;" trbidi="on"><br />
<table border="0" cellpadding="0" cellspacing="0" class="example" style="width: 100%;"><tbody>
<tr><td><br />
<h2 class="example">C - Code Example</h2><table border="0" cellpadding="0" cellspacing="0" class="example_code"><tbody>
<tr><td><br />
#include<stdio.h><br />
#include<conio.h><br />
<br />
void sum(int,int); // Function prototype declaration.<br />
void product(int,int); // Function prototype declaration.<br />
void substraction(int,int); // Function prototype declaration.<br />
void divide(int,int); // Function prototype declaration.<br />
<br />
void sum(int x,int y) // Definition function.<br />
{<br />
int z;<br />
z=x+y;<br />
printf("%d + %d = %d\n", x,y,z);<br />
}<br />
<br />
void product(int x,int y) // Definition function.<br />
{<br />
int z;<br />
z=x*y;<br />
printf("%d x %d = %d\n", x,y,z);<br />
}<br />
<br />
void substraction(int x,int y) // Definition function.<br />
{<br />
int z;<br />
<br />
z=x-y;<br />
printf("%d - %d = %d\n", x,y,z);<br />
}<br />
<br />
void divide(int x,int y) // Definition function.<br />
{<br />
float z;<br />
z=x/y;<br />
printf("%d / %d = %f\n", x,y,z);<br />
}<br />
<br />
<br />
void main()<br />
{<br />
int a,b,i;<br />
<br />
clrscr();<br />
<br />
printf("\n\n***********Calculator : Type number***********\n\n");<br />
printf("Type first number : ");<br />
scanf("%d",&a);<br />
printf("\nType second number : ");<br />
scanf("%d",&b);<br />
<br />
clrscr();<br />
printf("\n\n***********Calculator : Choose operation***********\n\n");<br />
printf("Select an option for perform the calculation task for these two numbers %d and %d\n\n",a,b);<br />
<br />
printf("Choose option \n\n");<br />
printf("for \n'+' : (1)'\n'x' : (2)\n'-' : (3)\n'/' : (4) : ");<br />
printf("\n\nType here : ");<br />
scanf("%d",&i);<br />
<br />
clrscr();<br />
printf("\n\n***********Calculator : Result (%d and %d)***********\n\n",a,b);<br />
<br />
printf("Results is : ");<br />
<br />
<br />
switch(i)<br />
{<br />
<br />
case 1 : sum(a,b);break; // Calling function.<br />
case 2 : product(a,b);break; // Calling function.<br />
case 3 : substraction(a,b);break; // Calling function.<br />
case 4 : divide(a,b);break; // Calling function.<br />
default : printf("\nYou put invalid input!!!"); // Calling function.<br />
break;<br />
}<br />
<br />
printf("\n\n***********Thanks for using it***********\n\n");<br />
printf("\n\n\n\n\t\t\t\tCreated by : Pawan Mall");<br />
getch();<br />
}</td></tr>
</tbody></table><a class="bt vtip" href="http://hifun.x10.mx/c-soft/FUNCTION.EXE" style="width: 400;" title="<img src='http://3.bp.blogspot.com/-ZwHZR_TB_ek/TiChj8ZOCsI/AAAAAAAAFGs/FYg5DcUmyhI/s1600/download.png' style='float:left;' /> <b> Click here for Download file : <span style='color:red;'>Calculator</span> </b> ">Download file : Calculator</a></td></tr>
</tbody></table></div><br />
</div></div>Pawan Mallhttp://www.blogger.com/profile/13987592121022726798noreply@blogger.com0