## Forum Replies Created

Viewing 8 posts - 1 through 8 (of 8 total)
• Author
Posts
• in reply to: calculator programme #3263
``````
#include
#include
#include
main()
{
int a,b,sum,diff,prdct,ch;
double sr;
long sq,cube;
float c,d,ratio;
do
{
clrscr();
printf("nnntt*****Simple Calculator*****nn");
printf("tt**Operations**n");
printf("ttt*(2)Subtractionn");
printf("ttt*(3)Multiplicationn");
printf("ttt*(4)Divisionn");
printf("ttt*(5)Squaren");
printf("ttt*(6)Cuben");
printf("ttt*(7)SquareRootn");
printf("nEnter the number of your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1:
printf("nttEnter two numbers: ");
scanf("%d %d", &a,&b);
sum = a + b;
printf("nnttThe Sum is : %d", sum);
break;
case 2:
printf("nttEnter two numbers: ");
scanf("%d %d", &a,&b);
diff = a - b;
printf("nnttThe Difference is : %d", diff);
break;
case 3:
printf("nttEnter two numbers: ");
scanf("%d %d", &a,&b);
prdct = a * b;
printf("nnttThe Product is : %d", prdct);
break;
case 4:
printf("nttEnter two numbers: ");
scanf("%f %f", &c,&d);
ratio = c / d;
printf("nnttThe Quotient is : %f", ratio);
break;
case 5:
printf("nttEnter a number: ");
scanf("%d", &a);
sq = a * a;
printf("nnttThe Square of %d is : %d", a,sq);
break;
case 6:
printf("nttEnter a number: ");
scanf("%d", &a);
cube = a * a * a;
printf("nnttThe Cube of %d is : %d", a,cube);
break;
case 7:
printf("nttEnter a number: ");
scanf("%d", &a);
sr = sqrt(a);
printf("nnttThe SquareRoot of %d is : %f", a,sr);
break;
}
printf("nnnnntttPress 'x' to quit, any other key to continuen");
}
while (getch() != 'x');
}``````

in reply to: calculator programme #3262
``````#include
#include
#include
#include
#include
#include
void main()
{
char prev='1',current,*ch;
char *nums[]={" 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "," 0 "};
char *num[]={"1","2","3","4","5","6","7","8","9","0"};
initgraph(&gd,&gm,"");
textbox t;
initmouse();
showmouse();
t.make(150,50,160);
for(i=0,j=100;i<10;i++,j+=40)
b.make(j,100,nums);
sub.make(140,150," - ");
equal.make(260,150," = ");
mul.make(180,150," * ");
div.make(220,150," / ");
exit.make(350,400," EXIT ");
ac.make(300,150," AC ");
j=0;
while(1)
{
setcolor(WHITE);
while(!flag)//This while terminates when user is finished inputting a number
//i.e. when he presses '+', '-', '*', '/'
{
for(i=0;i<10;i++)
{
if(b.click())
{
t.append(num),j++,k=1;//display the number in textbox
break;
}
}
if(j==1&&k==1)
t.write(""),t.append(num);
current='+',flag=1;
else if(sub.click())
current='-',flag=1;
else if(equal.click())
current='=',flag=1;
else if(mul.click())
current='*',flag=1;
else if(div.click())
current='/',flag=1;
else if(exit.click())
flag=2;// flag==2 indicates user wants to exit.
else if(ac.click())
{
prev='1';
t.write("");
}
k=0;
}//End of second while loop
//Now Calculate the result.
if(flag==2)
break;//flagg==2, go out of the main loop to exit.
if(prev=='1')
else if(prev=='+')
else if(prev=='-')
else if(prev=='*')
else if(prev=='/'&&(atoi(t.text))==0)
msgbox("Cannot divide by zero"),prev='1',t.write("");
else if(prev=='/')
flag=0,j=0;
prev=current;
t.write(ch);
}
closegraph();
}
``````
#3333

The first few numbers of Lucas sequences which is a variation of Fibonacci sequence are sequence are
1 3 4 7 11 18 29
a) Design a program in C to generate Lucas sequence.
b) Develop a function to calculate sum of first n odd integers.

``````#include
#include
void main()
{
int num,i;
unsigned long n1=1,n2=3,s;
clrscr();
printf("nENTER A NUMBER: ");
scanf("%d",&num);
printf("nLUCAS SEQUENCE UPTO %d NUMBERS IS: n",num);
printf("%lu %lu",n1,n2);
for(i=1;i<=num-2;i++)
{
s=n1+n2;
printf(" %lu",s);
n1=n2;
n2=s;
}
getch();
}``````
in reply to: base conversion #3264

A program to convert a decimal number to its equivalent binary number.

``````#include
#include
void main()
{
unsigned long dec;
int a,c=0,i;
clrscr();
printf("nENTER A DECIMAL NUMBER: ");
scanf("%lu",&dec);
printf("n%lu IN BINARY FORMAT: ",dec);
while(dec>0)
{
a[c]=dec%2;
dec=dec/2;
c++;
}
for(i=c-1;i>=0;i--)
printf("%d",a);
getch();
} ``````
in reply to: C program to display own source code as output #3275

i think you should use file handling and open the file which you are making it will show your file on compiling the program

in reply to: C program to display own source code as output #3274

i am not ab;e to write whole program at this time but i give you the clue that you should use file handling and open your file on which you are writting the program

in reply to: hi this is kishore #3279

you should refer to lakshmikant question i replies at that

in reply to: Re: c programming #3290

Write a program to print a triangle (Floyd Triangle) like the following: –
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

``````#include
#include
void main()
{
int num,i,j,k,s=40;
clrscr();
printf("nENTER THE NUMBER OF LINES: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
for(j=1;j<=s;j++)
printf(" ");
for(k=1;k<=i;k++)
printf("%d",k);
for(k=i-1;k>0;k--)
printf("%d",k);
printf("n");
s--;
}
getch();
}``````
Viewing 8 posts - 1 through 8 (of 8 total)