488 views

Uploaded by Heo Mập

Attribution Non-Commercial (BY-NC)

- Fortran 95 Answers of Exercises
- Writing Your First Delphi Program
- PLSQL for Beginners Workbook
- ControlLogix Training Manual
- DX100 Operator's Manual
- 3HAC7783_1_RB_en
- Jntua b.tech Eee r13 Syllabus
- Introduction to game design
- Using the DG4000 SpreadSheet
- Comparison Table Load (CTBL),Instruksi dasar PLC
- C++ Tutorial
- Siemens Sinumerik 840d Programming Guide
- Function in C
- BYOB
- Class Concept Questions
- Computer Programming
- CBSE 12th Exam Computer Science Paper
- MD050_Functional Design Template
- 3HAC050947 EnRAPID Overview
- 9A05501 Principles of Programming Languages

You are on page 1of 12

1. Write a program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference, and quotient of the two numbers. 2. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words "is larger." If the numbers are equal, print the message "These numbers are equal." 3. Write a program that reads in the radius of a circle as an integer and prints the circle's diameter, circumference and area. Use the constant value 3.14159 for p. Do all calculations in output statements. [Note: In this chapter, we have discussed only integer constants and variables 4. Write a program that reads an integer and determines and prints whether it is odd or even. 5. Write a program that inputs a five-digit integer, separates the integer into its individual digits and prints the digits separated from one another by three spaces each. [Hint: Use the integer division and modulus operators.] For example, if the user types in 42339, the program should print: 4 2 3 3 9 6. Write a program to solve a set of equations:

y a1 x b1 y a2 x b2

7. Write a program to solve a 2nd-order equation: ax2 bx c 0 - Input: a,b,c - Output: roots (if any) for all cases.

1. Calculate the value of p from the infinite series

Print a table that shows the approximate value of p after each of the first 1,000 terms of this series. 2. Write a program that prints the following diamond shape. You may use output statements that print either a single asterisk (*) or a single blank. Maximize your use of repetition (with nested for statements) and minimize the number of output statements. * *** ***** ******* ********* ******* ***** *** *

Suppose we have a network of two resistors with the values 400 W and 200 W. Then our equation would be:

So the total resistance of our two-resistor network is 133.3 W. Write a program to compute the total resistance for any number of parallel resistors. 4. Write a program that converts numbers to words. Example: 895 results in ''eight nine five." 5. ("The Twelve Days of Christmas" Song) Write a program that uses repetition and switch statements to print the song "The Twelve Days of Christmas." One switch statement should be used to print the day (i.e., "First," "Second," etc.). A separate switch statement should be used to print the remainder of each verse. Programming for Engineers Lab.docx

INTERNATIONAL UNIVERSITY SCHOOL OF ELECTRICAL ENGINEERING (EE) The Twelve days of Christmas On the first day of Christmas my true love sent to me: A Partridge in a Pear Tree On the second day of Christmas my true love sent to me: Two Turtle Doves and a Partridge in a Pear Tree On the third day of Christmas my true love sent to me: Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the fourth day of Christmas my true love sent to me: Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the fifth day of Christmas my true love sent to me: Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the sixth day of Christmas my true love sent to me: Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the seventh day of Christmas my true love sent to me: Seven Swans a Swimming Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the eighth day of Christmas my true love sent to me: Eight Maids a Milking Seven Swans a Swimming Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the ninth day of Christmas my true love sent to me: Nine Ladies Dancing Eight Maids a Milking Seven Swans a Swimming Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the tenth day of Christmas my true love sent to me: Ten Lords a Leaping Nine Ladies Dancing Eight Maids a Milking Seven Swans a Swimming Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the eleventh day of Christmas my true love sent to me: Eleven Pipers Piping Ten Lords a Leaping Nine Ladies Dancing Eight Maids a Milking Seven Swans a Swimming Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree On the twelfth day of Christmas my true love sent to me: 12 Drummers Drumming Eleven Pipers Piping Ten Lords a Leaping Nine Ladies Dancing Eight Maids a Milking Seven Swans a Swimming Six Geese a Laying Five Golden Rings Four Calling Birds Three French Hens Two Turtle Doves and a Partridge in a Pear Tree

8. Write a program that asks the user to enter two integers, obtains the numbers from the user, and then prints the larger number followed by the words "is larger." If the numbers are equal, print the message "These numbers are equal." 9. Using the conditional operator, write a program that asks the user to enter three integers, and then display the median value among those numbers. 10. Write a program that asks the user to type in an integer n and n interger values at the terminal, and then display the minimum value among those numbers. 11. Write a program to solve a 2nd-order equation: aX2+bX+c=0 - Input: a, b, c - Output: roots (if any) for all cases. 12. Using the switch construct, write a program that converts numbers to words. Example: 895 results in ''eight nine five." Remember to display zero if the user types in just a 0. 13. Write a program that acts as a simple printing calculator. The program should allow the user to type in expressions of the form:

number operator

+ * / S E

The S operator tells the program to set the accumulatorto the typed-in number. The E operator tells the program that execution is to end. The arithmetic operations are performed on the contents of the accumulator with the number that was keyed in acting as the second operand.The following is a sample run showing how the program should operate:

Begin Calculations 10 S Set Accumulator to 10 = 10.000000 Contents of Accumulator 2 / Divide by 2 = 5.000000 Contents of Accumulator 55 Subtract 55 -50.000000 100.25 S Set Accumulator to 100.25 = 100.250000 4 * Multiply by 4 = 401.000000 0 E End of program = 401.000000 End of Calculations.

Make certain that the program detects division by zero and also checks for unknown operators.

LAB 4: C ARRAYS

1. Write a program that calculates the average of an array of 10 floating-point values. 2. What output do you expect from the following program? #include <stdio.h> int main (void) { int numbers[10] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int i, j; for ( j = 0; j < 10; ++j ) for ( i = 0; i < j; ++i ) numbers[j] += numbers[i]; for ( j = 0; j < 10; ++j ) printf ("%i ", numbers[j]); printf ("\n"); return 0; } 3. You dont need to use an array to generate Fibonacci numbers. You can simply use three variables: two to store the previous two Fibonacci numbers and one to store the current one. Rewrite program 7.3 so that arrays are not used. Because youre no longer using an array, you need to display each Fibonacci number as you generate it. 4. Using array, write a program that converts numbers to words. Example: 895 results in ''eight nine five." 5. Prime numbers can also be generated by an algorithm known as the Sieve of Erastosthenes. The algorithm for this procedure is presented here. Write a program that implements this algorithm. Have the program find all prime numbers up to n = 150.

LAB 5: C FUNCTIONS

Write functions to solve the following exercises. 14. Prints the following diamond shape (input: the size of diamond). * *** ***** ******* ********* ******* ***** *** * 15. Solve a set of equations: Y=a1x+b1 Y=a2x+b2 - Input: a1, b1, a2, b2 - Output: root (x,y), if any. 16. Write a program to solve a 2nd-order equation: ax2 + bx + c=0 - Input: a,b,c - Output: roots (if any) for all cases. 17. Convert numbers to words. Example: 895 results in ''eight nine five." 18. Convert a positive integer to another base. 19. Write a function that raises an integer to a positive integer power. Have the function return a long int, which represents the results of calculating xn. 20. Write a function prime that returns 1 if its argument is a prime number and returns 0 otherwise. 21. Write a function that prints all prime numbers n 22. Write a function to sort an array of integers into descending order. 23. Write a function called arraySum that takes two arguments: an integer array and the number of elements in the array. Have the function return as its result the sum of the elements in the array.

1. Write a function elapsed_time that takes as its arguments two time structures and returns a time structure that represents the elapsed time (in hours, minutes, and seconds) between the two times. So the call elapsed_time (time1, time2) where time1 represents 3:45:15 and time2 represents 9:44:03, should return a time structure that represents 5 hours, 58 minutes, and 48 seconds. Be careful with times that cross midnight. 2. Write a function called findString to determine if one character string exists inside another string. The first argument to the function should be the character string that is to be searched and the second argument is the string you are interested in finding. If the function finds the specified string, have it return the location in the source string where the string was found. If the function does not find the string, have it return 1. So, for example, the call index = findString ("a chatterbox", "hat"); searches the string "a chatterbox" for the string "hat". Because "hat" does exist inside the source string, the function returns 3 to indicate the starting position inside the source string where "hat" was found. 3. Write a function called removeString to remove a specified number of characters from a character string. The function should take three arguments: the source string, the starting index number in the source string, and the number of characters to remove. So, if the character array text contains the string "the wrong son", the call removeString (text, 4, 6); 4. Write a function called clockKeeper that takes as its argument a dateAndTime structure as defined in chapter 9 of the textbook. The function should call the timeUpdate function, and if the time reaches midnight, the function should call the dateUpdate function to switch over to the next day. Have the function return the updated dateAndTime structure. (In your program, make sure to

include the timeUpdate and dateUpdate functions which are already written in the textbook!) 5. We can calculate the number of elapsed days between two dates by computing the value of N for each of the two dates and then taking the difference, where N is calculated as follows:

Write a program that permits the user to type in two dates and then calculates the number of elapsed days between the two dates. Try to structure the program logically into separate functions. For example, you should have a function that accepts as an argument a date structure and returns the value of N computed as shown previously. This function can then be called twice, once for each date, and the difference taken to determine the number of elapsed days.

LAB 7: POINTERS

Write a function called insertEntry to insert a new entry into a linked list. Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in chapter 12 of the textbook), and a pointer to an element in the list after which the new entry is to be inserted. 6. The function developed in exercise 1 only inserts an element after an existing element in the list, thereby preventing you from inserting a new entry at the front of the list. How can you use this same function and yet overcome this problem? (Hint: Think about setting up a special structure to point to the beginning of the list.) 7. Write a function called removeEntry to remove an entry from a linked list. The sole argument to the procedure should be a pointer to the list. Have the function remove the entry after the one pointed to by the argument. (Why cant you remove the entry pointed to by the argument?) You need to use the special structure you set up in exercise 2 to handle the special case of removing the first element from the list. 8. Write a function called sort3 to sort three integers into ascending order. (This function is NOT to be implemented with arrays.) 9. Given the definition of a date structure as defined in chapter 12 of the textbook, write a function called dateUpdate that takes a pointer to a date structure as its argument and that updates the structure to the following day (see Program 9.4).

- Fortran 95 Answers of ExercisesUploaded byputih_138242459
- Writing Your First Delphi ProgramUploaded byapi-3738566
- PLSQL for Beginners WorkbookUploaded byrangafunny545
- ControlLogix Training ManualUploaded bybrainy
- DX100 Operator's ManualUploaded bygotchiex
- 3HAC7783_1_RB_enUploaded byMichał Marczak
- Jntua b.tech Eee r13 SyllabusUploaded byprasaad08
- Introduction to game designUploaded bySandile Mad-Mag
- Using the DG4000 SpreadSheetUploaded byRicardo Illa
- Comparison Table Load (CTBL),Instruksi dasar PLCUploaded byMad Atmadi
- C++ TutorialUploaded byeasy_fritzy
- Siemens Sinumerik 840d Programming GuideUploaded byGrosu Cosmin
- Function in CUploaded byKara Brown
- BYOBUploaded bypasko
- Class Concept QuestionsUploaded byShiva JK
- Computer ProgrammingUploaded byNageswara Rao Challa
- CBSE 12th Exam Computer Science PaperUploaded byrocky
- MD050_Functional Design TemplateUploaded bypdesiraju
- 3HAC050947 EnRAPID OverviewUploaded bywillgang
- 9A05501 Principles of Programming LanguagesUploaded bysivabharathamurthy
- Procedures and Functions _ DBMS _ Tutorialink.comUploaded bycompiler&automata
- HCLUploaded byArun Kumar
- 0RECVALSTCKUploaded byNITISCHO000
- assgnUploaded byZhichao Wang
- 01-05-02 SALSA TRAIN SO10 Create Standard TextUploaded byashwal
- Lab 3 Mikro p ReportUploaded byMuhammad Adnan
- 14107_02aUploaded byted
- Missra Decoder Userguide PodUploaded byCloud Beezer
- Ucos II RefmanUploaded byAhmed Abdelhakem
- 2 Unix ProgramsUploaded byvijuprakash

- 1ST DRAFT.docxUploaded bymerii
- GATE Pattern and syllabus for mechanicalUploaded byYugesh Rv
- LocAdaptFiltr_ICObookUploaded byAnonymous FGY7go
- AD8001Uploaded bysrescia
- 2nd PUC Mathematics March 2016Uploaded byANUSHA
- A new metric for program sizeUploaded byJohn Michael Williams
- All Purpose Excel Sheet Conversions)Uploaded byabdulwasayqazi
- C_EHVT_GHVTUploaded byJason Dennis
- Lectura3 - Interpretación de variogramasUploaded byBeatriz Ramos
- STA301- Statistics and Probability Solved 301Uploaded byAli Haider
- squential binding modelsUploaded byAnil Choubey
- InTech-Demodulation Reference Signal Design and Channel Estimation for Lte Advanced UplinkUploaded byPravat Karki
- 11-63-5-PB (1)Uploaded byAakasH Tivari
- mit quiz solutions 2Uploaded byjethros1
- PythonTutorialHandoutUploaded byeverlucy
- Maths For ScienceUploaded byArsalan Ahmed Usmani
- Quiz-1-Math-SPLBE-2016-Answers.pdfUploaded bycajaro
- 7FLWZD0P1299029431900Uploaded bymb
- High-damping,high-ReynoldsVIVtestsforenergyharnessingusingthe VIVACE converterUploaded bycroprobos
- Strain Mechanisms in Lead-Free Ferroelectrics for ActuatorsUploaded byJosé De Jesús Serralta
- 4 Unit III Statistical TestsUploaded byashu
- [Trading] Carolyn Boroden - How I Identify Powerful Setups Using Symmetry ( FibonacciUploaded byMakiyama Mariko
- Inequality Among World Citizens: 1820–1992Uploaded bymadworld26
- Conceptual Analysis, Definitions, WittgensteinUploaded byПетар Срдановић
- RTCSE 2018 | International Conference On Engineering TechnologyUploaded byDeepak Yadav
- ThermodynamicsUploaded byJuan Andres Vazquez Mancilla
- Control Valve Selection For Hydraulic SystemsUploaded byzoded
- Param HpgrUploaded byMeyer de la Cruz
- 1510.05594.pdfUploaded byradhakodirekka8732
- OSCA Individual AssignmentUploaded byVincent Lim