Anda di halaman 1dari 11

Homework Title / No: 01 Course Instructor: Ruchika Singhal Date of Allotment: 25-jan-2012 Students Roll No.

RE2R02A52

Course Code: CSE101T Course Tutor (if applicable) : Date of submission: 8th- Feb-2012 Section No.:E2R02

Declaration: I declare that this assignment is my individual work. I have not copied from any other students work or from any other source except where due acknowledgment is made explicitly in the text, nor has any part been written for me by another person. Students Signature: Gagandeep Singh Evaluators comments _____________________________________________________________________ Marks obtained: ___________ out of ______________________ Content of Homework should start from this page only:

Part-A Ques1: Design the flow chart to calculate the energy bill. Read the starting and ending meter reading. The charges are as follows: No of units consumed Rates in (Rs.) 200-500 3.50 100-200 2.50 Less than 100 1.50

Ans. The flow chart given on the next page:-

Ques3: Write an algorithm to find the prime numbers ranges from 1to 200 and also count the total prime numbers which are in the range of 1 to 200. Ans.

Ques2: Write the Pseudo code to enter the temperature in Fahrenheit and convert it Celsius. Formula to convert the temperature is tc = ((tf-32)*5)/9 Ans. Begin Read: tf, tc Print: enter the temperature in Fahrenheit a Set: tc = ((tf-32)*5)/9 Print: tf End

Ques.4. Company X sells merchandise to wholesale and outlets. Wholesale customers receive a 5% discount on all orders. The company also encourages both wholesale and retail customers to pay the cash on delivery by offering a 3% discount for this method of payment .Another 2% discount is given on orders of 500 or more units. Each column represents a certain type of order? Draw the decision table?

Ans. The decision table for the following problem on the next page and the rules for table are given as:1. If the wholesale or retail customer orders more than 500 units and they both pay cash on delivery they get 5% discount on order. 2. If the wholesale or retail customer order more than 500 units and not pay cash on the delivery they both get 2% discount on their order. 3. If the wholesale or retail customer orders less than 500 units and pay cash on delivery they get 3% discount on their order.

The decision table for the problem is given as follows:R1 R2 Wholesale or retail customer order more than 500 units Wholesale or retail customer pay cash on delivery 2% discount get 3% discount get 5% discount get Y Y __ __ X Y N X __ __ N Y __ X __ R3

Pat-B Ques.1:Write a program to sort six numbers and find the largest one by Using ladder of if Else. Ans. #include<stdio.h> #include<conio.h> void main() { int a,b,c,d,e,f; clrscr(); printf("Enter any six numbers: "); scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f); if((a>b && a>c && a>d && a>e && a>f))

printf(\n a is greater %d,a); else if((b>a && b>c && b>d && b>e && b>=f)) printf(\n b is greater %d,b); else if((c>a && c>b && c>d && c>e && c>f)) printf(\n c is greater %d,c); else if((d>a && d>b && d>e && d>e && d>f)) printf(\n d is greater %d,d); else if((e>a && e>b && e>c && e>d && e>f)) printf(\n e is greater %d,e); else printf(\n f is greater %d,f); getch(); } Ques2: Write a program to find the LCM and HCF of a number Ans. The c program to find LCM and HCF is given as:#include<stdio.h> #include<conio.h> void main() { int x,y,i,j,d,e; clrscr(); printf("Enter the two numbers :"); scanf("%d%d",&x,&y); for(i=1,j=1; i<=x,j<=y; i++,j++) { if((x%i==0) && (y%j==0) && (i==j)) d=i;

printf("The hcf of the two numbers in %d",d); } e=(x*y)/d; printf(\n lcm is:%d,e); getch(); }

Ques3: Write a program to compute the area of all the mathematical objects like (circle, rectangle, square, triangle etc.); with the help of the program, you are required to demonstrate the difference between variables and constants also. This program must contain all types of variables and constants possible in C Language. Every constant must be initialized and for every variable, user must enter the value at runtime. Test conditions are required to be given for the code Ans. The C program to find the area of circle, square, rectangle, triangle, cylinder etc. with the help of integer variables is given as:#include<stdio.h> #include<conio.h> void main( ) { int a,b,c,d,e,f,g ,h,ar1,ar2,ar3,ar4,ar5; clrscr( ); printf(enter the value of radius of circle:); scanf(%d,&a); printf(\n enter the side of square:); scanf(%d,&b); printf(\n enter the length and breath of rectangle:); scanf(%d %d,&c,&d); printf(\n enter the base and perpendicular length of triangle:); scanf(%d %d,&e,&f);

printf(\n enter the radius of base and height of a cylinder:); scanf(%d %d,&g,&h); ar1=3.14*a*a; ar2=b*b; ar3=c*d; ar4=(e*f)/2; ar5=2*3.14*g*h; printf(\n the area of circle:%d\n area of square:%d\n area of rectangle:%d\n area of triangle:%d\n area of cylinder:%d,ar1,ar2,ar3,ar4,ar5); getch( ); } When we press ctrl+F9 key to see the output the output screen is as OUTPUT SCREEN enter the value of radius of circle:10 enter the side of square:5 enter the length and breath of rectangle:2 3 enter the base and perpendicular length of triangle:4 5 enter the radius of base and height of a cylinder:10 10 the area of circle:314 area of square:25 area of rectangle:6 area of triangle:10 area of cylinder:628 This is the output given by the program its output depends upon the values entered by the user.So, this program can calculate every area. But one problem is occur with that

program. It can show output only for integer values. It means if we enter the value of radius of circle in decimal numbers it cant give the correct value of area of circle because it gives output only in integer cant give give output in decimal numbers. To solve this problem we have to use the float data type of variable in the place of integer data type. By using float data type we get correct answers in decimal values so if we change the data type in above program we get correct output Then the program looks like this:#include<stdio.h> #include<conio.h> void main( ) { ,

Float a,b,c,d,e,f,g,h,ar1,ar2,ar3,ar4,ar5; clrscr( ); printf(enter the value of radius of circle:); scanf(%f,&a); printf(\n enter the side of square:); scanf(%f,&b); printf(\n enter the length and breath of rectangle:); scanf(%f %f,&c,&d); printf(\n enter the base and perpendicular length of triangle:); scanf(%f %f,&e,&f); printf(\n enter the radius of base and height of a cylinder:); scanf(%f %f,&g,&h); ar1=3.14*a*a; ar2=b*b; ar3=c*d; ar4=(e*f)/2; ar5=2*3.14*g*h;

printf(\n the area of circle:%f\n area of square:%f\n area of rectangle:%f\n area of triangle:%f\n area of cylinder:%f,ar1,ar2,ar3,ar4,ar5); getch( ); } Moreover by this program we get output depending upon the values entered by user. If we want to make same program with float constant the program is as follows:#include<stdio.h> #include<conio.h> void main( ) { ,

Float a=1.2,b=1.5,c=2.2,d=1.2,e=1.5,f=0.5,g=10.0,h=5.2,ar1,ar2,ar3,ar4,ar5; clrscr( ); printf(enter the value of radius of circle:); scanf(%f,&a); printf(\n enter the side of square:); scanf(%f,&b); printf(\n enter the length and breath of rectangle:); scanf(%f %f,&c,&d); printf(\n enter the base and perpendicular length of triangle:); scanf(%f %f,&e,&f); printf(\n enter the radius of base and height of a cylinder:); scanf(%f %f,&g,&h); ar1=3.14*a*a; ar2=b*b; ar3=c*d; ar4=(e*f)/2; ar5=2*3.14*g*h;

printf(\n the area of circle:%f\n area of square:%f\n area of rectangle:%f\n area of triangle:%f\n area of cylinder:%f,ar1,ar2,ar3,ar4,ar5); getch( ); } By doing this program when we run it we get only some constant values of area always. This program depends upon the values of float constant By doing these programs it is clear that variables are the values whose value vary during the execution of program. Constants are predefined and their value remains same during the execution of program. Ques4: Write a program to find the value of following Expression: (e^-x +e^+x)/2 Here e is constant with value 2.71 and x can be any float number. Ans. The c program to find above expression is given as:#include<stdio.h> #include<conio.h> #include<math.h> void main() { float e=2.71, x, a; clrscr( ); printf (enter the value of x:); scanf(%f,&x); a=(pow(e,-x)+pow(e,x))/2; printf(%f,a); getch( ); }

-------------------------------------------End of assignment----------------------------------------

Anda mungkin juga menyukai