Tuesday, July 14, 2009

C programme...?

I wrote a programme of calculator in C language. And it has two or three error so pl do correct them. And send me correct answer.


Prog. is:





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void calsum(int a,int b);


void calsub(int a,int b);


void calmul(int a,int b);


void caldiv(float a,float b);


/*void calmod(int a,int b); */


void calsqr(int a);


void calcue(int a);


void calfac(long int a);


void main()


{


int l,m,n,ch;


clrscr();


printf("\t\t==========\n");


printf("\t\t Menu ");


printf("\t\t==========\n");


printf("\t\t 1 Add\n");


printf("\t\t 2 Sub\n");


printf("\t\t 3 Mul\n");


printf("\t\t 4 Div\n");


printf("\t\t 5 Factorail\n");


printf("\t\t 6 Square\n");


printf("\t\t 7 Cube\n");


/*printf("\t\t 8 Mod\n"); */


printf("\t\t Enter your choice \n");


scanf("%d",ch);


printf("\t\t =====\t");


switch(ch)


{


case 1:


printf("\t\tEnter two number : ");


scanf("%d%d",%26amp;l,%26amp;m);


calsum(l,m);


break;


case 2:


printf("\t\tEnter two numbers " );


scanf("%d%d",%26amp;l,%26amp;m);


calsub(l,m);


break;


case 3:


printf("\t\t Enter two numbers" );


scanf("%d%d",%26amp;l,%26amp;m);


calmul(l,m);


break;


case 4:


printf("\t\t Enter two numbers : ");


scanf("%s%s",%26amp;l,%26amp;m);


caldiv(l,m);


break;


case 5:


printf("\t\t Enter any no : ");


scanf("%ld",%26amp;l);


calfac(l);


break;


case 6:


printf("\t\t Enter any no : ");


scanf("%d",%26amp;l);


calsqr(l);


break;


case 7:


printf("\t\t Enter any no : ");


scanf("%d",%26amp;l);


calcue(l);


break;


/*


case 8:


printf("\t\t Enter any no : ");


scanf("%d",%26amp;l);


calmod(l);


break;*/


default:


printf("\t It is wrong choice : ");


}


getch();


}


void calsum(int a,int b)


{


int c;


c=a+b;


printf("Addition=%d",c);


}


void calsub(int a,int b)


{


int c;


c=a-b;


printf("Substance=%d",c);


}


void calmul(int a,int b)


{


int c;


c=a*b;


printf("Multiply=%d",c);


}


void caldiv(float a,float b)


{


float c;


c=a/b;


printf("Divide=%d",c);


}


void calsqr(int a)


{


int c;


c=a*a;


printf("Square=%d",c);


}


void calcue(int a)


{


int c;


c=a*a*a;


printf("Cube=%d",c);


} /*


void calmod(int a,int b)


{


int c;


c=a%b;


printf("Mod=%d",c);


} */


void calfac(long int a)


{


long int i,fct;


fct=1;


for(i=a;i%26gt;=1;i--)


{


fct=fct*i;


}


printf("Factorail=%d",fct);


}

C programme...?
i really can't find any thing wrong in here


but if u can send the error message and the line number i may be able to help u
Reply:1. in scan statement of switch case


correction:- scanf("%d",%26amp;ch);


2. mistake in caldiv function


correction:-


void caldiv(int a,int b)


{


float c;


c=a/b;


printf("Divide=%f",c);


}


4.mistake in case 4 in scanf statement,


correction:- scanf("%d%d",%26amp;l,%26amp;m); Report It

Reply:scanf("%s%s",%26amp;l,%26amp;m);


should not be used Report It

Reply:you have not put %26amp; in the scanf statement above the switch casae
Reply:It's "program", not "programme".





Rawlyn.


No comments:

Post a Comment