1 /*This is program of calculator*/
2 /*Author- Programmed guy Rohit*/
3 #include<stdio.h>
4 float prod(float,float);
5 float divide(float,float);
6 float add(float,float);
7 float sub(float,float);
8 int main()
9 {
10 float n1,n2;
11 char sym,choice;
12 printf("calculator program\n\n" );
13 scanf("%f%c%f",&n1,&sym,&n2);
14 if(sym=='*')
15 printf("\n%f",prod(n1,n2));
16 if(sym=='/')
17 printf("\n%f",divide(n1,n2));
18 if(sym=='+') /*demo of nested if*/
19 printf("\n%f",add(n1,n2));
20 if(sym=='-')
21 printf("\n%f",sub(n1,n2));
22 printf("\nWould you like to continue?\n[y/n]\n"); //use choice keyword to
23 scanf("%s",&choice); //use again this
24 if(choice=='y'||choice=='y') //program
25 main(); //with yes or no
26 } //option*/
27 float prod(float m1,float m2)
28 {
29 return(m1*m2);
30 }
31 float divide(float m1,float m2)
32 {
33 return(m1/m2);
34 }
35 float add(float m1,float m2)
36 {
37 return(m1+m2);
38 }
39 float sub(float m1,float m2)
40 {
41 return(m1-m2);
42 }
43
Tuesday, 26 June 2012
Calculator programming in c
Loop in c programming
1 #include <stdio.h>
2
3 int
4 main (void)
5 {
6 int time;
7
8 /* the loop */
9 for (time=60; time>=0; time=time-1)
10 {
11 printf ("%d ", time);
12 }
13
14 printf ("\n\nLIFTOFF!\n\n");
15
16 return(0);
17 }
Subscribe to:
Posts (Atom)