Forum Replies Created
- AuthorPosts
- yeswanthParticipant1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374<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 />}yeswanthParticipant1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#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 />yeswanthParticipant
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.1234567891011121314151617181920#include <br />#include <br />void main()<br />{<br />int num,i;<br />unsigned long n1=1,n2=3,s;<br />clrscr();<br />printf("nENTER A NUMBER: ");<br />scanf("%d",&num);<br />printf("nLUCAS SEQUENCE UPTO %d NUMBERS IS: n",num);<br />printf("%lu %lu",n1,n2);<br />for(i=1;i<=num-2;i++)<br />{<br />s=n1+n2;<br />printf(" %lu",s);<br />n1=n2;<br />n2=s;<br />}<br />getch();<br />}yeswanthParticipantA program to convert a decimal number to its equivalent binary number.
1234567891011121314151617181920#include <stdio.h><br />#include <conio.h><br />void main()<br />{<br />unsigned long dec;<br />int a[25],c=0,i;<br />clrscr();<br />printf("nENTER A DECIMAL NUMBER: ");<br />scanf("%lu",&dec);<br />printf("n%lu IN BINARY FORMAT: ",dec);<br />while(dec>0)<br />{<br />a[c]=dec%2;<br />dec=dec/2;<br />c++;<br />}<br />for(i=c-1;i>=0;i--)<br />printf("%d",a);<br />getch();<br />}yeswanthParticipanti think you should use file handling and open the file which you are making it will show your file on compiling the program
yeswanthParticipanti 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
yeswanthParticipantyou should refer to lakshmikant question i replies at that
yeswanthParticipantWrite 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 1123456789101112131415161718192021#include <stdio.h><br />#include <conio.h><br />void main()<br />{<br />int num,i,j,k,s=40;<br />clrscr();<br />printf("nENTER THE NUMBER OF LINES: ");<br />scanf("%d",&num);<br />for(i=1;i<=num;i++)<br />{<br />for(j=1;j<=s;j++)<br />printf(" ");<br />for(k=1;k<=i;k++)<br />printf("%d",k);<br />for(k=i-1;k>0;k--)<br />printf("%d",k);<br />printf("n");<br />s--;<br />}<br />getch();<br />} - AuthorPosts