From 3e884be9036ac044e95b4c04afeeeeedf270857c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 6 Jul 2023 04:53:52 +0000 Subject: [PATCH 01/19] updated logs --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 5643293..eaea3f5 100644 --- a/README.md +++ b/README.md @@ -1538,6 +1538,7 @@ individual structure members using pointer notation. 1. Write a program using pointers to read in an array of integers and print its elements in reverse order. +- [sadman](solutions/sadman/12/1.c) 2. We know that the roots of a quadratic equation of the form @@ -1549,32 +1550,38 @@ Write a function to calculate the roots. The function must use two pointer parameters, one to receive the coefficients a, b, and c, and the other to send the roots to the calling function. +- [sadman](solutions/sadman/12/2.c) 3. Write a function that receives a sorted array of integers and an integer value, and inserts the value in its correct place. +- [sadman](solutions/sadman/12/3.c) 4. Write a function using pointers to add two matrices and to return the resultant matrix to the calling function. +- [sadman](solutions/sadman/12/4.c) 5. Using pointers, write a function that receives a character string and a character as argument and deletes all occurrences of this character in the string. The function should return the corrected string with no holes. +- [sadman](solutions/sadman/12/5.c) 6. Write a function day_name that receives a number n and returns a pointer to a character string containing the name of the corresponding day. The day names should be kept in a static table of character strings local to the function. +- [sadman](solutions/sadman/12/6.c) 7. Write a program to read in an array of names and to sort them in alphabetical order. Use sort function that receives pointers to the functions strcmp and swap.sort in turn should call these functions via the pointers. +- [sadman](solutions/sadman/12/7.c) 8. Given an array of sorted list of integer numbers, write a function to search for a particular item, using @@ -1588,27 +1595,34 @@ all values greater than the middle element can be ignored. That is, in one attempt, we eliminate one half the list. This search can be applied recursively till the target value is found.) +- [sadman](solutions/sadman/12/8.c) 9. Write a function (using a pointer parameter) that reverses the elements of a given array. +- [sadman](solutions/sadman/12/9.c) 10. Write a function (using pointer parameters) that compares two integer arrays to see whether they are identical. The function returns 1 if they are identical, 0 otherwise. +- [sadman](solutions/sadman/12/10.c) 11. Write a C program to insert a substring into another string by using function and pointers. +- [sadman](solutions/sadman/12/11.c) 12. Write a C program that uses the pointer increment operations to demonstrate the scale factor. +- [sadman](solutions/sadman/12/12.c) 13. Write a C program that displays the addresses and values pointed by an array of pointers. +- [sadman](solutions/sadman/12/13.c) 14. Write a C program that uses pointers to demonstrate initialization of structure members. +- [sadman](solutions/sadman/12/14.c) ## Chapter 13 From 8b7d456f33fcf4e65a172d1b4583ec953732c438 Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Thu, 6 Jul 2023 12:39:18 +0600 Subject: [PATCH 02/19] question c11 | Correction Co-authored-by: NAYEMA --- README.md | 296 +++++++++++++++++++++++++---------------------- questions/11.txt | 62 ++++++---- 2 files changed, 201 insertions(+), 157 deletions(-) diff --git a/README.md b/README.md index eaea3f5..5a39d4f 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ Excersise solutions for the book "Programming in ANSI C" by E. Balagurusamy (eig 1. Write a program to display the equation of a line in the form `ax + by = c` for `a = 5, b = 8 and c = 18`. -- [monir](solutions/monir/2/1.c) - [rusni](solutions/rusni/2/1.c) +- [monir](solutions/monir/2/1.c) 2. Write a C program that uses an in-built function to draw a 3D bar. @@ -56,8 +56,8 @@ for `a = 5, b = 8 and c = 18`. ... 5 x 10 = 50 ``` -- [monir](solutions/monir/2/3.c) - [rusni](solutions/rusni/2/3.c) +- [monir](solutions/monir/2/3.c) 4. Given the values of three variables a, b and c, write a program to compute and display the value of x, where `x = a / ( b - c )` @@ -67,13 +67,13 @@ Execute your program for the following values: (b) a = 300, b = 70, c = 70 ``` Comment on the output in each case. -- [monir](solutions/monir/2/4.c) - [rusni](solutions/rusni/2/4.c) +- [monir](solutions/monir/2/4.c) 5. Write a C program that reads the value of distance travelled by a car and the time taken for the same. Next, compute the speed at which the car travelled. -- [monir](solutions/monir/2/5.c) - [rusni](solutions/rusni/2/5.c) +- [monir](solutions/monir/2/5.c) 6. Write a C program to print the current system date. - [monir](solutions/monir/2/6.c) @@ -203,12 +203,12 @@ Indian currency notes. 1. Write a program that reads a floating-point number and then displays the right-most digit of the integral part of the number. -- [sharafat](solutions/sharafat/4/1.c) - [sadman](solutions/sadman/4/1.c) +- [sharafat](solutions/sharafat/4/1.c) 2. Modify the above program to display the two right most digits of the integral part of the number. -- [sharafat](solutions/sharafat/4/2.c) - [sadman](solutions/sadman/4/2.c) +- [sharafat](solutions/sharafat/4/2.c) 3. Given an integer number, write a program that displays the number as follows: ``` @@ -223,8 +223,8 @@ For example, the number 5678 will be displayed as 7 8 8 ``` -- [sharafat](solutions/sharafat/4/3.c) - [sadman](solutions/sadman/4/3.c) +- [sharafat](solutions/sharafat/4/3.c) 4. The straight-line method of computing the yearly depreciation of the value of an item is given by ``` @@ -232,8 +232,8 @@ For example, the number 5678 will be displayed as ``` Write a program to determine the salvage value of an item when the purchase price, years of service, and the annual depreciation are given. -- [sharafat](solutions/sharafat/4/4.c) - [sadman](solutions/sadman/4/4.c) +- [sharafat](solutions/sharafat/4/4.c) 5. Write a program that will read a real number from the keyboard and print the following output in one line: @@ -242,8 +242,8 @@ Smallest integer The given Lergest integer not less than number not greater than the number the number ``` -- [sharafat](solutions/sharafat/4/5.c) - [sadman](solutions/sadman/4/5.c) +- [sharafat](solutions/sharafat/4/5.c) 6. The total distance travelled by a vehicle in t seconds is given by ``` @@ -253,8 +253,8 @@ distance = ut + ( a t*2 ) / 2 program to evaluate the distance travelled at regular intervals of time, given the values of u and a. > The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of u and a . -- [sharafat](solutions/sharafat/4/6.c) - [sadman](solutions/sadman/4/6.c) +- [sharafat](solutions/sharafat/4/6.c) 7. In inventory management, the Economic Order Quantity for a single item is given by ``` @@ -266,8 +266,8 @@ TBO = sqrt ((2* setup costs) / (demand rate * holding cost per unit time)) ``` Write a program to compute EOQ and TBO, given demand rate (items per unit time), setup costs (per order), and the holding cost (per item per unit time). -- [sharafat](solutions/sharafat/4/7.c) - [sadman](solutions/sadman/4/7.c) +- [sharafat](solutions/sharafat/4/7.c) 8. For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency is given by @@ -276,22 +276,22 @@ Frequency = sqrt ((1 / L*C )- (R*R / 4*C*C) ``` It is desired to study the variation of this frequency with C (capacitance). Write a program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01. -- [sharafat](solutions/sharafat/4/8.c) - [sadman](solutions/sadman/4/8.c) +- [sharafat](solutions/sharafat/4/8.c) 9. Write a program to read a four digit integer and print the sum of its digits. Hint: Use / and % operators. -- [sharafat](solutions/sharafat/4/9.c) - [sadman](solutions/sadman/4/9.c) +- [sharafat](solutions/sharafat/4/9.c) 10. Given three values, write a program to read three values from keyboard and print out the largest of them without using if statement. -- [sharafat](solutions/sharafat/4/10.c) - [sadman](solutions/sadman/4/10.c) +- [sharafat](solutions/sharafat/4/10.c) 11. Write a program to read two integer values m and n and to decide and print whether m is a multiple of n. -- [sharafat](solutions/sharafat/4/11.c) - [sadman](solutions/sadman/4/11.c) +- [sharafat](solutions/sharafat/4/11.c) 12. Write a program to read three values using scanf statement and print the following results: ``` @@ -300,13 +300,13 @@ them without using if statement. (c) Largest of the three (d) Smallest of the three ``` -- [sharafat](solutions/sharafat/4/12.c) - [sadman](solutions/sadman/4/12.c) +- [sharafat](solutions/sharafat/4/12.c) 13. The cost of one type of mobile service is Rs. 250 plus Rs. 1.25 for each call made over and above 100 calls. Write a program to read customer codes and calls made and print the bill for each customer. -- [sharafat](solutions/sharafat/4/13.c) - [sadman](solutions/sadman/4/13.c) +- [sharafat](solutions/sharafat/4/13.c) 14. Write a program to print a table of sin and cos functions for the interval from 0 to 180 degrees in increments of 15 a shown here. @@ -317,8 +317,8 @@ degrees in increments of 15 a shown here. | ... | ... | ... | | ... | ... | ... | | 180 | ... | ... | -- [sharafat](solutions/sharafat/4/14.c) - [sadman](solutions/sadman/4/14.c) +- [sharafat](solutions/sharafat/4/14.c) 15. Write a program to compute the values of square roots and squares of the numbers 0 to 100 in steps 10 and print the output in a tabular form as shown below. @@ -327,35 +327,35 @@ degrees in increments of 15 a shown here. | ------ | ----------- | ------ | | 0 | 0 | 0 | | 100 | 10 | 10000 | -- [sharafat](solutions/sharafat/4/15.c) - [sadman](solutions/sadman/4/15.c) +- [sharafat](solutions/sharafat/4/15.c) 16. Write a program to illustrate the use of cast operator in a real life situation. -- [sharafat](solutions/sharafat/4/16.c) - [sadman](solutions/sadman/4/16.c) +- [sharafat](solutions/sharafat/4/16.c) 17. Write a C program to shift the given data by two bits to the left. -- [sharafat](solutions/sharafat/4/17.c) - [sadman](solutions/sadman/4/17.c) +- [sharafat](solutions/sharafat/4/17.c) 18. Write a C program to compute the value of the expression `x=a-b/3+c*2-1`. -- [sharafat](solutions/sharafat/4/18.c) - [sadman](solutions/sadman/4/18.c) +- [sharafat](solutions/sharafat/4/18.c) 19. Write a C program to input a date value and determine whether the entered day, month, and year values are valid. -- [sharafat](solutions/sharafat/4/19.c) - [sadman](solutions/sadman/4/19.c) +- [sharafat](solutions/sharafat/4/19.c) 20. Write a C program to input the sides of a triangle and determine whether the triangle is isoceles or not. -- [sharafat](solutions/sharafat/4/20.c) - [sadman](solutions/sadman/4/20.c) +- [sharafat](solutions/sharafat/4/20.c) 21. Write a C program that reads two numbers and performs their division. If the division is not possible, then an error messgage, ‘Division not possible’ is displayed. -- [sharafat](solutions/sharafat/4/21.c) - [sadman](solutions/sadman/4/21.c) +- [sharafat](solutions/sharafat/4/21.c) 22. Input the value of 4 variables a, b, c and d and compute the resultant value of following expressions: @@ -364,8 +364,8 @@ expressions: (a + b) * c / d a + (b * c) / d ``` -- [sharafat](solutions/sharafat/4/22.c) - [sadman](solutions/sadman/4/22.c) +- [sharafat](solutions/sharafat/4/22.c) ## Chapter 5 @@ -377,9 +377,9 @@ display the same in the following formats: PROCESSING (c) W.P. ``` -- [sharafat](solutions/sharafat/5/1.c) - [sadman](solutions/sadman/5/1.c) - [NAYEMA](solutions/NAYEMA/5/1.c) +- [sharafat](solutions/sharafat/5/1.c) 2. Write a program to read the values of x and y and print the results of the following expressions in one @@ -389,15 +389,15 @@ line: (b) (x+y) /2 (c) (x+y)(x–y) ``` -- [sharafat](solutions/sharafat/5/2.c) - [sadman](solutions/sadman/5/2.c) - [NAYEMA](solutions/NAYEMA/5/2.c) +- [sharafat](solutions/sharafat/5/2.c) 3. Write a program to read the following numbers, round them off to the nearest integers and print out the results in integer form: 35.7 50.21 – 23.73 – 46.45 -- [sharafat](solutions/sharafat/5/3.c) - [sadman](solutions/sadman/5/3.c) - [NAYEMA](solutions/NAYEMA/5/3.c) +- [sharafat](solutions/sharafat/5/3.c) 4. Write a program that reads 4 floating point values in the range, 0.0 to 20.0, and prints a horizontal bar chart to represent these values using the character * as the fill character. For the purpose of the chart, @@ -409,9 +409,9 @@ represented as follows. * * * * ``` > Note that the actual values are shown at the end of each bar. -- [sharafat](solutions/sharafat/5/4.c) - [sadman](solutions/sadman/5/4.c) - [NAYEMA](solutions/NAYEMA/5/4.c) +- [sharafat](solutions/sharafat/5/4.c) 5. Write an interactive program to demonstrate the process of multiplication. The program should ask the user to enter two two-digit integers and print the product of integers as shown below. @@ -425,9 +425,9 @@ the user to enter two two-digit integers and print the product of integers as sh Add them 1665 _______________ ``` -- [sharafat](solutions/sharafat/5/5.c) - [sadman](solutions/sadman/5/5.c) - [NAYEMA](solutions/NAYEMA/5/5.c) +- [sharafat](solutions/sharafat/5/5.c) 6. Write a program to read three integers from the keyboard using one scanf statement and output them on one line using: @@ -436,9 +436,9 @@ them on one line using: (b) only one printf with conversion specifiers, and (c) only one printf without conversion specifiers. ``` -- [sharafat](solutions/sharafat/5/6.c) - [sadman](solutions/sadman/5/6.c) - [NAYEMA](solutions/NAYEMA/5/6.c) +- [sharafat](solutions/sharafat/5/6.c) 7. Write a program that prints the value 10.45678 in exponential format with the following specifications: ``` @@ -446,9 +446,9 @@ them on one line using: (b) correct to four decimal places; and (c) correct to eight decimal places. ``` -- [sharafat](solutions/sharafat/5/7.c) - [sadman](solutions/sadman/5/7.c) - [NAYEMA](solutions/NAYEMA/5/7.c) +- [sharafat](solutions/sharafat/5/7.c) 8. Write a program to print the value 345.6789 in fixed-point format with the following specifications: ``` @@ -456,9 +456,9 @@ them on one line using: (b) correct to five decimal places; and (c) correct to zero decimal places. ``` -- [sharafat](solutions/sharafat/5/8.c) - [sadman](solutions/sadman/5/8.c) - [NAYEMA](solutions/NAYEMA/5/8.c) +- [sharafat](solutions/sharafat/5/8.c) 9. Write a program to read the name ANIL KUMAR GUPTA in three parts using the scanf statement and to display the same in the following format using the printf statement. @@ -467,9 +467,9 @@ to display the same in the following format using the printf statement. (b) A.K. GUPTA (c) GUPTA A.K. ``` -- [sharafat](solutions/sharafat/5/9.c) - [sadman](solutions/sadman/5/9.c) - [NAYEMA](solutions/NAYEMA/5/9.c) +- [sharafat](solutions/sharafat/5/9.c) 10. Write a program to read and display the following table of data. ``` @@ -478,26 +478,26 @@ to display the same in the following format using the printf statement. Motor 450 5786.70 ``` > The name and code must be left-justified and price must be right justified. -- [sharafat](solutions/sharafat/5/10.c) - [sadman](solutions/sadman/5/10.c) - [NAYEMA](solutions/NAYEMA/5/10.c) +- [sharafat](solutions/sharafat/5/10.c) 11. Write a C program to print inventory stock report using some sample data. The report should show item code, quantity and inventory location as formatted output. -- [sharafat](solutions/sharafat/5/11.c) - [sadman](solutions/sadman/5/11.c) - [NAYEMA](solutions/NAYEMA/5/11.c) +- [sharafat](solutions/sharafat/5/11.c) 12. Write a C program to display the Pascal’s triangle. -- [sharafat](solutions/sharafat/5/12.c) - [sadman](solutions/sadman/5/12.c) - [NAYEMA](solutions/NAYEMA/5/12.c) +- [sharafat](solutions/sharafat/5/12.c) 13. Write a C program to input a currency value in Dollars and display its equivalent Euro and INR amounts. You may use current exchange rate for conversion purpose. -- [sharafat](solutions/sharafat/5/13.c) - [sadman](solutions/sadman/5/13.c) - [NAYEMA](solutions/NAYEMA/5/13.c) +- [sharafat](solutions/sharafat/5/13.c) 14. Write a C program to display the following pattern. ``` @@ -512,9 +512,9 @@ INR amounts. You may use current exchange rate for conversion purpose. 15. Write a C program to input an investment amount and compute its fixed deposit cumulative return after 10 years at arate of interest of 8.75%. -- [sharafat](solutions/sharafat/5/15.c) - [sadman](solutions/sadman/5/15.c) - [NAYEMA](solutions/NAYEMA/5/15.c) +- [sharafat](solutions/sharafat/5/15.c) ## Chapter 6 @@ -526,14 +526,14 @@ NUMBER IS ODD (a) without using else option and (b) with else option. ``` -- [sharafat](solutions/sharafat/6/1.c) - [sadman](solutions/sadman/6/1.c) +- [sharafat](solutions/sharafat/6/1.c) 2. Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7. -- [sharafat](solutions/sharafat/6/2.c) - [sadman](solutions/sadman/6/2.c) - [NAYEMA](solutions/NAYEMA/6/2.c) +- [sharafat](solutions/sharafat/6/2.c) 3. A set of two linear equations with two unknowns x1 and x2 is given below: ``` @@ -547,8 +547,8 @@ The set has a unique solution ``` provided the denominator `ad – cb` is not equal to zero. Write a program that will read the values of constants a, b, c, d, m, and n and compute the values of x 1 and x 2. An appropriate message should be printed if ad – cb = 0. -- [sharafat](solutions/sharafat/6/3.c) - [NAYEMA](solutions/NAYEMA/6/3.c) +- [sharafat](solutions/sharafat/6/3.c) 4. Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students: @@ -563,9 +563,9 @@ students: (h) in the range 0 to 40. ``` The program should use a minimum number of if statements. -- [sharafat](solutions/sharafat/6/4.c) - [sadman](solutions/sadman/6/4.c) - [NAYEMA](solutions/NAYEMA/6/4.c) +- [sharafat](solutions/sharafat/6/4.c) 5. Admission to a professional course is subject to the following conditions: ``` @@ -577,9 +577,9 @@ The program should use a minimum number of if statements. or, Total in Mathematics and Physics >= 150 Given the marks in the three subjects, write a program to process the applications to list the eligible candidates. -- [sharafat](solutions/sharafat/6/5.c) - [sadman](solutions/sadman/6/5.c) - [NAYEMA](solutions/NAYEMA/6/5.c) +- [sharafat](solutions/sharafat/6/5.c) 6. Write a program to print a two-dimensional Square Root Table as shown below, to provide the square root of any number from 0 to 9.9. For example, the value x will give the square root of 3.2 and y the @@ -594,9 +594,9 @@ square root of 3.9. | 0.3 | | | x | | y | | ... | | | | | | | 0.9 | | | | | | -- [sharafat](solutions/sharafat/6/6.c) - [sadman](solutions/sadman/6/6.c) - [NAYEMA](solutions/NAYEMA/6/6.c) +- [sharafat](solutions/sharafat/6/6.c) 7. Shown below is a Floyd’s triangle. ``` @@ -616,9 +616,9 @@ square root of 3.9. 0 1 0 1 1 0 1 0 1 ``` -- [sharafat](solutions/sharafat/6/7.c) - [sadman](solutions/sadman/6/7.c) - [NAYEMA](solutions/NAYEMA/6/7.c) +- [sharafat](solutions/sharafat/6/7.c) 8. A cloth showroom has announced the following seasonal discounts on purchase of items: > @@ -629,14 +629,14 @@ square root of 3.9. | 101 - 200 | 5% | 7.5% | | 201 - 300 | 7.5% | 10% | | Above 300 | 10% | 15% | -- [sharafat](solutions/sharafat/6/8.c) - [sadman](solutions/sadman/6/8.c) - [NAYEMA](solutions/NAYEMA/6/8.c) +- [sharafat](solutions/sharafat/6/8.c) Write a program using switch and if statements to compute the net amount to be paid by a customer -- [sharafat](solutions/sharafat/6/9.c) - [sadman](solutions/sadman/6/9.c) - [NAYEMA](solutions/NAYEMA/6/9.c) +- [sharafat](solutions/sharafat/6/9.c) 9. Write a program that will read the value of x and evaluate the following function, ``` @@ -650,8 +650,8 @@ using, (b) else if statements, and (c) conditional operator ? : ``` -- [sharafat](solutions/sharafat/6/10.c) - [sadman](solutions/sadman/6/10.c) +- [sharafat](solutions/sharafat/6/10.c) 10. Write a program to compute the real roots of a quadratic equation ``` @@ -673,13 +673,13 @@ constants a, b and c and print the values of x 1 and x 2. ``` Test your program with appropriate data so that all logical paths are working as per your design. Incorporate appropriate output messages. -- [sharafat](solutions/sharafat/6/11.c) - [sadman](solutions/sadman/6/11.c) +- [sharafat](solutions/sharafat/6/11.c) 11. Write a program to read three integer values from the keyboard and displays the output stating that they are the sides of right-angled triangle. -- [sharafat](solutions/sharafat/6/12.c) - [sadman](solutions/sadman/6/12.c) +- [sharafat](solutions/sharafat/6/12.c) 12. An electricity board charges the following rates for the use of electricity: ``` @@ -691,21 +691,21 @@ All users are charged a minimum of Rs. 100 as meter charge. If the total amount then an additional surcharge of 15% of total amount is charged. Write a program to read the names of users and number of units consumed and print out the charges with names. -- [sharafat](solutions/sharafat/6/13.c) - [sadman](solutions/sadman/6/13.c) +- [sharafat](solutions/sharafat/6/13.c) 13. Write a program to compute and display the sum of all integers that are divisible by 6 but not divisible by 4 and lie between 0 and 100. The program should also count and display the number of such values. -- [sharafat](solutions/sharafat/6/14.c) - [sadman](solutions/sadman/6/14.c) +- [sharafat](solutions/sharafat/6/14.c) 14. Write an interactive program that could read a positive integer number and decide whether the number is a prime number and display the output accordingly. Modify the program to count all the prime numbers that lie between 100 and 200. > NOTE : A prime number is a positive integer that is divisible only by 1 or by itself. -- [sharafat](solutions/sharafat/6/15.c) - [sadman](solutions/sadman/6/15.c) +- [sharafat](solutions/sharafat/6/15.c) 15. Write a program to read a double-type value x that represents angle in radians and a character-type variable T that represents the type of trigonometric function and display the value of @@ -715,13 +715,13 @@ variable T that represents the type of trigonometric function and display the va (c) tan (x), if t or T is assigned to T ``` using, (i) if......else statement , and (ii) switch statement. -- [sharafat](solutions/sharafat/6/16.c) - [sadman](solutions/sadman/6/16.c) +- [sharafat](solutions/sharafat/6/16.c) 16. Write a C program to input the numeric week day value (starting from Monday as 1) and display the corresponding name of the week day. -- [sharafat](solutions/sharafat/6/17.c) - [sadman](solutions/sadman/6/17.c) +- [sharafat](solutions/sharafat/6/17.c) 17. Write a C program to input two numbers a and b and display whether ``` @@ -729,8 +729,8 @@ corresponding name of the week day. (b) b is greater than b (c) or, a and b are equal ``` -- [sharafat](solutions/sharafat/6/18.c) - [sadman](solutions/sadman/6/18.c) +- [sharafat](solutions/sharafat/6/18.c) 18. Write a C program to input the total percentage of marks of a student and display its Division using below rules: @@ -739,14 +739,14 @@ below rules: (b) Greater than or equal to 60 percent and less than 80 per cent - “Second Division” (c) Less than 60 percent - “Third Division" ``` -- [sharafat](solutions/sharafat/6/19.c) - [sadman](solutions/sadman/6/19.c) +- [sharafat](solutions/sharafat/6/19.c) 19. Using Switch case block, input the name of the month from the user and display the corresponding number of days in that month. -- [sharafat](solutions/sharafat/6/20.c) - [sadman](solutions/sadman/6/20.c) - [NAYEMA](solutions/NAYEMA/6/20.c) +- [sharafat](solutions/sharafat/6/20.c) 20. Write a C program that inputs a string and counts the number of capital and small alphabets in that string. @@ -763,12 +763,12 @@ should be written as ``` > ( Hint: Use modulus operator to extract the last digit and the integer division by 10 to get the n–1 digit number from the n digit number.) -- [sharafat](solutions/sharafat/7/1.c) - [sadman](solutions/sadman/7/1.c) +- [sharafat](solutions/sharafat/7/1.c) 2. Write a program to compute the sum of the digits of a given integer number. -- [sharafat](solutions/sharafat/7/2.c) - [sadman](solutions/sadman/7/2.c) +- [sharafat](solutions/sharafat/7/2.c) 3. The numbers in the sequence ``` @@ -777,8 +777,8 @@ digit number from the n digit number.) are called Fibonacci numbers. Write a program using a do....while loop to calculate and print the first m Fibonacci numbers. > ( Hint: After the first two numbers in the series, each number is the sum of the two preceding numbers.) -- [sharafat](solutions/sharafat/7/3.c) - [sadman](solutions/sadman/7/3.c) +- [sharafat](solutions/sharafat/7/3.c) 4. Write a program to evaluate the following investment equation ``` @@ -799,8 +799,8 @@ be recursively written as ``` That is, the value of money at the end of first year becomes the principal amount for the next year and so on.) -- [sharafat](solutions/sharafat/7/4.c) - [sadman](solutions/sadman/7/4.c) +- [sharafat](solutions/sharafat/7/4.c) 5. Write programs to print the following outputs using for loops. ``` @@ -811,18 +811,18 @@ so on.) 4 4 4 4 * * 5 5 5 5 5 * ``` -- [sharafat](solutions/sharafat/7/5.c) - [sadman](solutions/sadman/7/5.c) +- [sharafat](solutions/sharafat/7/5.c) 6. Write a program to read the age of 100 persons and count the number of persons in the age group 50 to 60. Use for and continue statements. -- [sharafat](solutions/sharafat/7/6.c) - [sadman](solutions/sadman/7/6.c) +- [sharafat](solutions/sharafat/7/6.c) 7. Rewrite the program of case study 7.4 (plotting of two curves) using else...if constructs instead of continue statements. -- [sharafat](solutions/sharafat/7/7.c) - [sadman](solutions/sadman/7/7.c) +- [sharafat](solutions/sharafat/7/7.c) 8. Write a program to print a table of values of the function ``` @@ -841,8 +841,8 @@ for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as foll | . | | | | | | | . | | | | | | |9.0| | | | | | -- [sharafat](solutions/sharafat/7/8.c) - [sadman](solutions/sadman/7/8.c) +- [sharafat](solutions/sharafat/7/8.c) 9. Write a program using for and if statement to display the capital letter S in a grid of 15 rows and 18 columns as shown below. @@ -864,8 +864,8 @@ for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as foll ***-----------**** **------------**** ``` -- [sharafat](solutions/sharafat/7/9.c) - [sadman](solutions/sadman/7/9.c) +- [sharafat](solutions/sharafat/7/9.c) 10. Write a program to compute the value of Euler’s number e, that is used as the base of natural logarithms. Use the following formula. @@ -874,8 +874,8 @@ logarithms. Use the following formula. ``` Use a suitable loop construct. The loop must terminate when the difference between two successive values of e is less than 0.00001. -- [sharafat](solutions/sharafat/7/10.c) - [sadman](solutions/sadman/7/10.c) +- [sharafat](solutions/sharafat/7/10.c) 11. Write programs to evaluate the following functions to 0.0001% accuracy. ``` @@ -883,8 +883,8 @@ successive values of e is less than 0.00001. (b) cosx = 1 – x 2 /2! + x 4 /4! – x 6 /6! + . . . . . (c) SUM = 1 + (1/2) 2 + (1/3) 3 + (1/4) 4 + … … ``` -- [sharafat](solutions/sharafat/7/11.c) - [sadman](solutions/sadman/7/11.c) +- [sharafat](solutions/sharafat/7/11.c) 12. The present value (popularly known as book value) of an item is given by the relationship. ``` @@ -898,8 +898,8 @@ successive values of e is less than 0.00001. If P is considered the scrap value at the end of useful life of the item, write a program to compute the useful life in years given the original cost, depreciation rate, and the scrap value. The program should request the user to input the data interactively. -- [sharafat](solutions/sharafat/7/12.c) - [sadman](solutions/sadman/7/12.c) +- [sharafat](solutions/sharafat/7/12.c) 13. Write a program to print a square of size 5 by using the character N as shown below: ``` @@ -911,16 +911,16 @@ The program should request the user to input the data interactively. n n n n n n n n n n ``` > n is used insted of S in the above figure LOL. -- [sharafat](solutions/sharafat/7/13.c) - [sadman](solutions/sadman/7/13.c) +- [sharafat](solutions/sharafat/7/13.c) 14. Write a program to graph the function ``` y = sin (x) ``` in the interval 0 to 180 degrees in steps of 15 degrees. Use the concepts discussed in the Case Study 4 in Chapter 7. -- [sharafat](solutions/sharafat/7/14.c) - [sadman](solutions/sadman/7/14.c) +- [sharafat](solutions/sharafat/7/14.c) 15. Modify the program of Exercise 7.16 to print the character S instead of N at the center of the square as shown below. ``` @@ -931,17 +931,17 @@ in the interval 0 to 180 degrees in steps of 15 degrees. Use the concepts discus n n n n n ``` > n is used insted of S in the above figure LOL. -- [sharafat](solutions/sharafat/7/15.c) - [sadman](solutions/sadman/7/15.c) +- [sharafat](solutions/sharafat/7/15.c) 16. Given a set of 10 two-digit integers containing both positive and negative values, write a program using for loop to compute the sum of all positive values and print the sum and the number of values added. The program should use scanf to read the values and terminate when the sum exceeds 999. Do not use goto statement. -- [sharafat](solutions/sharafat/7/16.c) - [sadman](solutions/sadman/7/16.c) +- [sharafat](solutions/sharafat/7/16.c) 17. Write a C program to display a coloured line. -- [sharafat](solutions/sharafat/7/17.c) - [sadman](solutions/sadman/7/17.c) +- [sharafat](solutions/sharafat/7/17.c) 18. Write a C program to display the following pattern. ``` @@ -951,8 +951,8 @@ The program should use scanf to read the values and terminate when the sum excee C D E F 5 6 7 8 9 ``` -- [sharafat](solutions/sharafat/7/18.c) - [sadman](solutions/sadman/7/18.c) +- [sharafat](solutions/sharafat/7/18.c) 19. Write a C program to display the following pattern: ``` @@ -962,8 +962,8 @@ The program should use scanf to read the values and terminate when the sum excee 1 2 1 1 ``` -- [sharafat](solutions/sharafat/7/19.c) - [sadman](solutions/sadman/7/19.c) +- [sharafat](solutions/sharafat/7/19.c) 20. Write a C program to display the following pattern: ``` @@ -986,8 +986,8 @@ y = mx + c ``` and the values of m and c are given y the following equations: > All summations are from 1 to n. -- [sharafat](solutions/sharafat/8/1.c) - [sadman](solutions/sadman/8/1.c) +- [sharafat](solutions/sharafat/8/1.c) 2. The daily maximum temperatures recorded in 10 cities during the month of January (for all 31 days) have been tabulated. Write a program to read the table elements into a two-dimensional array temperature , and to find the city and day corresponding to @@ -995,12 +995,12 @@ Write a program to read the table elements into a two-dimensional array temperat (a) the highest temperature and (b) the lowest temperature. ``` -- [sharafat](solutions/sharafat/8/2.c) - [sadman](solutions/sadman/8/2.c) +- [sharafat](solutions/sharafat/8/2.c) 3. An election is contested by 5 candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count . In case, a number read is outside the range 1 to 5, the ballot should be considered as a ‘spoilt ballot’ and the program should also count the number of spoilt ballots. -- [sharafat](solutions/sharafat/8/3.c) - [sadman](solutions/sadman/8/3.c) +- [sharafat](solutions/sharafat/8/3.c) 4. The following set of numbers is popularly known as Pascal’s triangle. ``` @@ -1017,8 +1017,8 @@ If we denote rows by i and columns by j, then any element p ij = p i–1 ,j–1 + p i–1 ,j ``` Write a program to calculate the elements of the Pascal triangle for 10 rows and print the results. -- [sharafat](solutions/sharafat/8/4.c) - [sadman](solutions/sadman/8/4.c) +- [sharafat](solutions/sharafat/8/4.c) 5. The annual examination results of 100 students are tabulated as follows: > @@ -1034,12 +1034,12 @@ Write a program to read the data and determine the following: (b) The highest marks in each subject and the Roll No. of the student who secured it. (c) The student who obtained the highest total marks. ``` -- [sharafat](solutions/sharafat/8/5.c) - [sadman](solutions/sadman/8/5.c) +- [sharafat](solutions/sharafat/8/5.c) 6. Given are two one-dimensional arrays A and B which are sorted in ascending order. Write a program to merge them into a single sorted array that contains every item from arrays A and B, in ascending order. -- [sharafat](solutions/sharafat/8/6.c) - [sadman](solutions/sadman/8/6.c) +- [sharafat](solutions/sharafat/8/6.c) 7. Two matrices that have the same number of rows and columns can be multiplied to produce a third matrix. Consider the following two matrices. The product of A and B is a third matrix C of size n¥ n where each element of C is given by the following equation. @@ -1047,8 +1047,8 @@ The product of A and B is a third matrix C of size n¥ n where each element of C multiplied_matrix[i][j] += first_matrix[i][k] * second_matrix[k][j]; ``` Write a program that will read the values of elements of A and B and produce the product matrix C. -- [sharafat](solutions/sharafat/8/7.c) - [sadman](solutions/sadman/8/7.c) +- [sharafat](solutions/sharafat/8/7.c) 8. Write a program that fills a five-by-five matrix as follows: ``` @@ -1057,12 +1057,12 @@ Write a program that will read the values of elements of A and B and produce the - Right to left diagonal with zeros Display the contents of the matrix using not more than two printf statements. ``` -- [sharafat](solutions/sharafat/8/8.c) - [sadman](solutions/sadman/8/8.c) +- [sharafat](solutions/sharafat/8/8.c) 9. Selection sort is based on the following idea: Selecting the largest array element and swapping it with the last array element leaves an unsorted list whose size is 1 less than the size of the original list. If we repeat this step again on the unsorted list we will have an ordered list of size 2 and an unordered list size n–2 . When we repeat this until the size of the unsorted list becomes one, the result will be a sorted list. Write a program to implement this algorithm. -- [sharafat](solutions/sharafat/8/9.c) - [sadman](solutions/sadman/8/9.c) +- [sharafat](solutions/sharafat/8/9.c) 10. Develop a program to implement the binary search algorithm. This technique compares the search key value with the value of the element that is midway in a “sorted” list. Then; ``` @@ -1072,20 +1072,20 @@ Display the contents of the matrix using not more than two printf statements. ``` Repeat this “divide-and-conquer” strategy until we have a match. If the list is reduced to one nonmatching element, then the list does not contain the key value. Use the sorted list created in Exercise 8.9 or use any other sorted list. -- [sharafat](solutions/sharafat/8/10.c) - [sadman](solutions/sadman/8/10.c) +- [sharafat](solutions/sharafat/8/10.c) 11. Write a program that will compute the length of a given character string. -- [sharafat](solutions/sharafat/8/11.c) - [sadman](solutions/sadman/8/11.c) +- [sharafat](solutions/sharafat/8/11.c) 12. Write a program that will count the number occurrences of a specified character in a given line of text. Test your program. -- [sharafat](solutions/sharafat/8/12.c) - [sadman](solutions/sadman/8/12.c) +- [sharafat](solutions/sharafat/8/12.c) 13. Write a program to read a matrix of size m ¥ n and print its transpose. -- [sharafat](solutions/sharafat/8/13.c) - [sadman](solutions/sadman/8/13.c) +- [sharafat](solutions/sharafat/8/13.c) 14. Every book published by international publishers should carry an International Standard Book Number (ISBN). It is a 10 character 4 part number as shown below. ``` @@ -1096,42 +1096,42 @@ The first part denotes the region, the second represents publisher, the third id Sum = (1 × first digit) + (2 × second digit) + (3 ×third digit) + - - - - + (9 × ninth digit). ``` Check digit is the remainder when sum is divided by 11. Write a program that reads a given ISBN number and checks whether it represents a valid ISBN. -- [sharafat](solutions/sharafat/8/14.c) - [sadman](solutions/sadman/8/14.c) +- [sharafat](solutions/sharafat/8/14.c) 15. Write a program to read two matrices A and B and print the following: ``` (a) A + B; and (b) A – B. ``` -- [sharafat](solutions/sharafat/8/15.c) - [sadman](solutions/sadman/8/15.c) +- [sharafat](solutions/sharafat/8/15.c) 16. Write a C program to compute the sum of elements of two one-dimensional arrays and store the corresponding result in another array. -- [sharafat](solutions/sharafat/8/16.c) - [sadman](solutions/sadman/8/16.c) +- [sharafat](solutions/sharafat/8/16.c) 17. Write a C program to identify and count all the odd numbers in an array and calculate their sum. -- [sharafat](solutions/sharafat/8/17.c) - [sadman](solutions/sadman/8/17.c) +- [sharafat](solutions/sharafat/8/17.c) 18. Write a C program to input an amount in Indian currency and deduce the minimum currency denomination for that amount. -- [sharafat](solutions/sharafat/8/18.c) - [sadman](solutions/sadman/8/18.c) +- [sharafat](solutions/sharafat/8/18.c) 19. Write a C program to input a Roman number and compute its decimal equivalent. - [sharafat](solutions/sharafat/8/19.c) 20. Write a C program to input two NXN matrices and deduce their sum and product. -- [sharafat](solutions/sharafat/8/20.c) - [sadman](solutions/sadman/8/20.c) +- [sharafat](solutions/sharafat/8/20.c) ## Chapter 9 1. Write a program, which reads your name from the keyboard and outputs a list of ASCII codes, which represent your name. -- [sharafat](solutions/sharafat/9/1.c) - [sadman](solutions/sadman/9/1.c) - [NAYEMA](solutions/NAYEMA/9/1.c) +- [sharafat](solutions/sharafat/9/1.c) 2. Write a program to do the following: ``` @@ -1141,29 +1141,29 @@ Check digit is the remainder when sum is divided by 11. Write a program that rea (d) To output the message ‘try again’, if the answer is wrong. (e) To display the correct answer when the answer is wrong even at the third attempt and stop. ``` -- [sharafat](solutions/sharafat/9/2.c) - [sadman](solutions/sadman/9/2.c) - [NAYEMA](solutions/NAYEMA/9/2.c) +- [sharafat](solutions/sharafat/9/2.c) 3. Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character. -- [sharafat](solutions/sharafat/9/3.c) - [sadman](solutions/sadman/9/3.c) - [NAYEMA](solutions/NAYEMA/9/3.c) +- [sharafat](solutions/sharafat/9/3.c) 4. Write a program which will read a text and count all occurrences of a particular word. -- [sharafat](solutions/sharafat/9/4.c) - [sadman](solutions/sadman/9/4.c) - [NAYEMA](solutions/NAYEMA/9/4.c) +- [sharafat](solutions/sharafat/9/4.c) 5. Write a program which will read a string and rewrite it in the alphabetical order. For example, the word STRING should be written as GINRST. -- [sharafat](solutions/sharafat/9/5.c) - [sadman](solutions/sadman/9/5.c) - [NAYEMA](solutions/NAYEMA/9/5.c) +- [sharafat](solutions/sharafat/9/5.c) 6. Write a program to replace a particular word by another word in a given string. For example, the word “PASCAL” should be replaced by “C” in the text “It is good to program in PASCAL language.” -- [sharafat](solutions/sharafat/9/6.c) - [sadman](solutions/sadman/9/6.c) - [NAYEMA](solutions/NAYEMA/9/6.c) +- [sharafat](solutions/sharafat/9/6.c) 7. A Maruti car dealer maintains a record of sales of various vehicles in the following form: @@ -1179,8 +1179,8 @@ Write a program to read this data into a table of strings and output the details - [sadman](solutions/sadman/9/7.c) 8. Write a program that reads a string from the keyboard and determines whether the string is a palindrome or not. (A string is a palindrome if it can be read from left and right with the same meaning. For example, Madam and Anna are palindrome strings. Ignore capitalization). -- [sharafat](solutions/sharafat/9/8.c) - [sadman](solutions/sadman/9/8.c) +- [sharafat](solutions/sharafat/9/8.c) 9. Write program that reads the cost of an item in the form RRRR.PP (Where RRRR denotes Rupees and PP denotes Paise) and converts the value to a string of words that expresses the numeric value in words. For example, if we input 125.75, the output should be “ONE HUNDRED TWENTY FIVE AND PAISE SEVENTY FIVE”. @@ -1199,25 +1199,25 @@ and produce the following output list: (b) List sorted on roll numbers. (c) List sorted on marks (rank-wise list) ``` -- [sharafat](solutions/sharafat/9/10.c) - [sadman](solutions/sadman/9/10.c) +- [sharafat](solutions/sharafat/9/10.c) 11. Write a program to read two strings and compare them using the function strncmp( ) and print a message that the first string is equal, less, or greater than the second one. -- [sharafat](solutions/sharafat/9/11.c) - [sadman](solutions/sadman/9/11.c) +- [sharafat](solutions/sharafat/9/11.c) 12. Write a program to read a line of text from the keyboard and print out the number of occurrences of a given substring using the function strstr ( ). -- [sharafat](solutions/sharafat/9/12.c) - [sadman](solutions/sadman/9/12.c) +- [sharafat](solutions/sharafat/9/12.c) 13. Write a program that will copy m consecutive characters from a string s1 beginning at position n into another string s2. -- [sharafat](solutions/sharafat/9/13.c) - [sadman](solutions/sadman/9/13.c) +- [sharafat](solutions/sharafat/9/13.c) 14. Write a program to create a directory of students with roll numbers. The program should display the roll number for a specified name and vice-versa. -- [sharafat](solutions/sharafat/9/14.c) - [sadman](solutions/sadman/9/14.c) +- [sharafat](solutions/sharafat/9/14.c) 15. Given a string ``` @@ -1231,34 +1231,34 @@ Write a program that displays the following: 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5 ``` -- [sharafat](solutions/sharafat/9/15.c) - [sadman](solutions/sadman/9/15.c) +- [sharafat](solutions/sharafat/9/15.c) 16. Write a C program to compare two strings without using any string function. -- [sharafat](solutions/sharafat/9/16.c) - [sadman](solutions/sadman/9/16.c) +- [sharafat](solutions/sharafat/9/16.c) 17. Write a C program to find the largest and smallest sized word in a string. -- [sharafat](solutions/sharafat/9/17.c) - [sadman](solutions/sadman/9/17.c) +- [sharafat](solutions/sharafat/9/17.c) 18. Write a C program to replace all the white spaces in a string with double white spaces. -- [sharafat](solutions/sharafat/9/18.c) - [sadman](solutions/sadman/9/18.c) +- [sharafat](solutions/sharafat/9/18.c) 19. Write a C program to enter multiple strings and display them in lexicographical order. -- [sharafat](solutions/sharafat/9/19.c) - [sadman](solutions/sadman/9/19.c) +- [sharafat](solutions/sharafat/9/19.c) 20. Write a C program to concatenate two strings without using any string function. -- [sharafat](solutions/sharafat/9/20.c) - [sadman](solutions/sadman/9/20.c) +- [sharafat](solutions/sharafat/9/20.c) ## Chapter 10 1. Write a function exchange to interchange the values of two variables, say x and y. Illustrate the use of this function, in a calling function. Assume that x and y are defined as global variables. -- [Hridoy](solutions/Hridoy/10/1.c) - [sadman](solutions/sadman/10/1.c) +- [Hridoy](solutions/Hridoy/10/1.c) 2. Write a function space(x) that can be used to provide a space of x positions between two output numbers. Demonstrate its application. - [sadman](solutions/sadman/10/2.c) @@ -1369,12 +1369,14 @@ What modifications are required if we want to use the function in preparing the ## Chapter 11 -1. Define a structure data type called time_struct -containing three members integer hour, integer -minute and integer second . Develop a program +1. Define a structure data type called *time_struct* +containing three members integer *hour*, integer +*minute* and integer *second* . Develop a program that would assign values to the individual members and display the time in the following form: +``` 16:40:51 +``` - [sadman](solutions/sadman/11/1.c) 2. Modify the above program such that a function is @@ -1382,7 +1384,7 @@ used to input values to the members and another function to display the time. - [sadman](solutions/sadman/11/2.c) -3. Design a function update that would accept the +3. Design a function *update* that would accept the data structure designed in Exercise 11.1 and increments time by one second and returns the new time. (If the increment results in 60 seconds, then @@ -1393,30 +1395,36 @@ the hour member is incremented by one. Finally when the hour becomes 24, it is set to zero.) - [sadman](solutions/sadman/11/3.c) -4. Define a structure data type named date containing three - integer members day , month , and year. Develop an interactive +4. Define a structure data type named *date* containing three +integer members *day* , *month* , and *year*. Develop an interactive modular program to perform the following tasks: +``` (a) To read data into structure mem bers by a function (b) To validate the date entered by another function (c) To print the date in the format April 29, 2002 by a third function. +``` The input data should be three integers like 29, 4, and 2002 corresponding to day, month, and year. Examples of invalid data: +``` 31, 4, 2002 – April has only 30 days 29, 2, 2002 – 2002 is not a leap year +``` - [sadman](solutions/sadman/11/4.c) -5. Design a function update that accepts the date +5. Design a function *update* that accepts the *date* structure designed in Exercise 11.4 to increment the date by one day and return the new date. The following rules are applicable: +``` (a) If the date is the last day in a month, month should be incremented (b) If it is the last day in December, the year should be incremented (c) There are 29 days in February of a leap year +``` - [sadman](solutions/sadman/11/5.c) 6. Modify the input function used in Exercise 11.4 such @@ -1424,7 +1432,7 @@ that it reads a value that represents the date in the form of a long integer, like 19450815 for the date 15-8-1945 (August 15, 1945) and assigns suitable values to the members day, month , and year. -Use suitable algorithm to +> Use suitable algorithm to convert the long integer 19450815 into year, month and day. - [sadman](solutions/sadman/11/6.c) @@ -1432,6 +1440,7 @@ and day. 7. Add a function called nextdate to the program designed in Exercise 11.4 to perform the following task: +``` (a) Accepts two arguments, one of the structure data containing the present date and the second an integer that represents the number of days to be @@ -1440,23 +1449,28 @@ added to the present date. structure containing the next date correctly. Note that the next date may be in the next month or even the next year. +``` - [sadman](solutions/sadman/11/7.c) -8. Use the date structure defined in Exercise 11.4 to +8. Use the *date* structure defined in Exercise 11.4 to store two dates. Develop a function that will take these two dates as input and compares them. -(a) It returns 1, if the date1 is earlier than date2 -(b) It returns 0, if date1 is later date +``` +(a) It returns 1, if the *date1* is earlier than *date2* +(b) It returns 0, if *date1* is later date +``` - [sadman](solutions/sadman/11/8.c) 9. Define a structure to represent a vector (a series of integer values) and write a modular program to perform the following tasks: +``` (a) To create a vector (b) To modify the value of a given element (c) To multiply by a scalar value (d) To display the vector in the form (10, 20, 30, . . . . . ..) +``` - [sadman](solutions/sadman/11/9.c) 10. Add a function to the program of Exercise 11.9 that @@ -1464,30 +1478,34 @@ accepts two vectors as input parameters and return the addition of two vectors. - [sadman](solutions/sadman/11/10.c) -11. Create two structures named metric and British which store -the values of distances. The metric structure stores +11. Create two structures named *metric* and *British* which store +the values of distances. The *metric* structure stores the values in metres and centimetres and the British structure stores the values in feet and inches. Write a program that reads values for the structure variables and adds values contained in one variable -of metric to the contents of another variable of -British. The program should display the result in the +of *metric* to the contents of another variable of +*British*. The program should display the result in the format of feet and inches or metres and centimetres as required. - [sadman](solutions/sadman/11/11.c) -12. Define a structure named census with the +12. Define a structure named *census* with the following three members: +``` (a) A character array city [ ] to store names (b) A long integer to store population of the city (c) A float member to store the literacy level +``` Write a program to do the following: +``` (a) To read details for 5 cities randomly using an array variable (b) To sort the list alphabetically (c) To sort the list based on literacy level (d) To sort the list based on population (e) To display sorted lists +``` - [sadman](solutions/sadman/11/12.c) 13. Define a structure that can describe an hotel. It @@ -1495,27 +1513,31 @@ should have members that include the name, address, grade, average room charge, and number of rooms. Write functions to perform the following operations: +``` (a) To print out hotels of a given grade in order of charges. (b) To print out hotels with room charges less than a given value. +``` - [sadman](solutions/sadman/11/13.c) -14. Define a structure called cricket that will describe +14. Define a structure called *cricket* that will describe the following information: +``` player name team name batting average -Using cricket, declare an array player with 50 +``` +Using *cricket*, declare an array *player* with 50 elements and write a program to read the information about all the 50 players and print a team-wise list containing names of players with their batting average. - [sadman](solutions/sadman/11/14.c) -15. Design a structure student_record to contain +15. Design a structure *student_record* to contain name, date of birth, and total marks obtained. Use -the date structure designed in Exercise 11.4 to +the *date* structure designed in Exercise 11.4 to represent the date of birth. Develop a program to read data for 10 students in a class and list them rank-wise. diff --git a/questions/11.txt b/questions/11.txt index f928a25..ddf5db1 100644 --- a/questions/11.txt +++ b/questions/11.txt @@ -1,15 +1,17 @@ -1. Define a structure data type called time_struct -containing three members integer hour, integer -minute and integer second . Develop a program +1. Define a structure data type called *time_struct* +containing three members integer *hour*, integer +*minute* and integer *second* . Develop a program that would assign values to the individual members and display the time in the following form: +``` 16:40:51 +``` 2. Modify the above program such that a function is used to input values to the members and another function to display the time. -3. Design a function update that would accept the +3. Design a function *update* that would accept the data structure designed in Exercise 11.1 and increments time by one second and returns the new time. (If the increment results in 60 seconds, then @@ -19,42 +21,49 @@ member is incremented by one. Then, if the result is the hour member is incremented by one. Finally when the hour becomes 24, it is set to zero.) -4. Define a structure data type named date containing three - integer members day , month , and year. Develop an interactive +4. Define a structure data type named *date* containing three +integer members *day* , *month* , and *year*. Develop an interactive modular program to perform the following tasks: +``` (a) To read data into structure mem bers by a function (b) To validate the date entered by another function (c) To print the date in the format April 29, 2002 by a third function. +``` The input data should be three integers like 29, 4, and 2002 corresponding to day, month, and year. Examples of invalid data: +``` 31, 4, 2002 – April has only 30 days 29, 2, 2002 – 2002 is not a leap year +``` -5. Design a function update that accepts the date +5. Design a function *update* that accepts the *date* structure designed in Exercise 11.4 to increment the date by one day and return the new date. The following rules are applicable: +``` (a) If the date is the last day in a month, month should be incremented (b) If it is the last day in December, the year should be incremented (c) There are 29 days in February of a leap year +``` 6. Modify the input function used in Exercise 11.4 such that it reads a value that represents the date in the form of a long integer, like 19450815 for the date 15-8-1945 (August 15, 1945) and assigns suitable values to the members day, month , and year. -Use suitable algorithm to +> Use suitable algorithm to convert the long integer 19450815 into year, month and day. 7. Add a function called nextdate to the program designed in Exercise 11.4 to perform the following task: +``` (a) Accepts two arguments, one of the structure data containing the present date and the second an integer that represents the number of days to be @@ -63,74 +72,87 @@ added to the present date. structure containing the next date correctly. Note that the next date may be in the next month or even the next year. +``` -8. Use the date structure defined in Exercise 11.4 to +8. Use the *date* structure defined in Exercise 11.4 to store two dates. Develop a function that will take these two dates as input and compares them. -(a) It returns 1, if the date1 is earlier than date2 -(b) It returns 0, if date1 is later date +``` +(a) It returns 1, if the *date1* is earlier than *date2* +(b) It returns 0, if *date1* is later date +``` 9. Define a structure to represent a vector (a series of integer values) and write a modular program to perform the following tasks: +``` (a) To create a vector (b) To modify the value of a given element (c) To multiply by a scalar value (d) To display the vector in the form (10, 20, 30, . . . . . ..) +``` 10. Add a function to the program of Exercise 11.9 that accepts two vectors as input parameters and return the addition of two vectors. -11. Create two structures named metric and British which store -the values of distances. The metric structure stores +11. Create two structures named *metric* and *British* which store +the values of distances. The *metric* structure stores the values in metres and centimetres and the British structure stores the values in feet and inches. Write a program that reads values for the structure variables and adds values contained in one variable -of metric to the contents of another variable of -British. The program should display the result in the +of *metric* to the contents of another variable of +*British*. The program should display the result in the format of feet and inches or metres and centimetres as required. -12. Define a structure named census with the +12. Define a structure named *census* with the following three members: +``` (a) A character array city [ ] to store names (b) A long integer to store population of the city (c) A float member to store the literacy level +``` Write a program to do the following: +``` (a) To read details for 5 cities randomly using an array variable (b) To sort the list alphabetically (c) To sort the list based on literacy level (d) To sort the list based on population (e) To display sorted lists +``` 13. Define a structure that can describe an hotel. It should have members that include the name, address, grade, average room charge, and number of rooms. Write functions to perform the following operations: +``` (a) To print out hotels of a given grade in order of charges. (b) To print out hotels with room charges less than a given value. +``` -14. Define a structure called cricket that will describe +14. Define a structure called *cricket* that will describe the following information: +``` player name team name batting average -Using cricket, declare an array player with 50 +``` +Using *cricket*, declare an array *player* with 50 elements and write a program to read the information about all the 50 players and print a team-wise list containing names of players with their batting average. -15. Design a structure student_record to contain +15. Design a structure *student_record* to contain name, date of birth, and total marks obtained. Use -the date structure designed in Exercise 11.4 to +the *date* structure designed in Exercise 11.4 to represent the date of birth. Develop a program to read data for 10 students in a class and list them rank-wise. From 0124a8b2612ebb7318a365755909dcf2746a72a2 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 6 Jul 2023 06:39:40 +0000 Subject: [PATCH 03/19] updated logs --- README.md | 234 +++++++++++++++++++++++++++--------------------------- 1 file changed, 117 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index 5a39d4f..7af1917 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ Excersise solutions for the book "Programming in ANSI C" by E. Balagurusamy (eig 1. Write a program to display the equation of a line in the form `ax + by = c` for `a = 5, b = 8 and c = 18`. -- [rusni](solutions/rusni/2/1.c) - [monir](solutions/monir/2/1.c) +- [rusni](solutions/rusni/2/1.c) 2. Write a C program that uses an in-built function to draw a 3D bar. @@ -56,8 +56,8 @@ for `a = 5, b = 8 and c = 18`. ... 5 x 10 = 50 ``` -- [rusni](solutions/rusni/2/3.c) - [monir](solutions/monir/2/3.c) +- [rusni](solutions/rusni/2/3.c) 4. Given the values of three variables a, b and c, write a program to compute and display the value of x, where `x = a / ( b - c )` @@ -67,13 +67,13 @@ Execute your program for the following values: (b) a = 300, b = 70, c = 70 ``` Comment on the output in each case. -- [rusni](solutions/rusni/2/4.c) - [monir](solutions/monir/2/4.c) +- [rusni](solutions/rusni/2/4.c) 5. Write a C program that reads the value of distance travelled by a car and the time taken for the same. Next, compute the speed at which the car travelled. -- [rusni](solutions/rusni/2/5.c) - [monir](solutions/monir/2/5.c) +- [rusni](solutions/rusni/2/5.c) 6. Write a C program to print the current system date. - [monir](solutions/monir/2/6.c) @@ -203,12 +203,12 @@ Indian currency notes. 1. Write a program that reads a floating-point number and then displays the right-most digit of the integral part of the number. -- [sadman](solutions/sadman/4/1.c) - [sharafat](solutions/sharafat/4/1.c) +- [sadman](solutions/sadman/4/1.c) 2. Modify the above program to display the two right most digits of the integral part of the number. -- [sadman](solutions/sadman/4/2.c) - [sharafat](solutions/sharafat/4/2.c) +- [sadman](solutions/sadman/4/2.c) 3. Given an integer number, write a program that displays the number as follows: ``` @@ -223,8 +223,8 @@ For example, the number 5678 will be displayed as 7 8 8 ``` -- [sadman](solutions/sadman/4/3.c) - [sharafat](solutions/sharafat/4/3.c) +- [sadman](solutions/sadman/4/3.c) 4. The straight-line method of computing the yearly depreciation of the value of an item is given by ``` @@ -232,8 +232,8 @@ For example, the number 5678 will be displayed as ``` Write a program to determine the salvage value of an item when the purchase price, years of service, and the annual depreciation are given. -- [sadman](solutions/sadman/4/4.c) - [sharafat](solutions/sharafat/4/4.c) +- [sadman](solutions/sadman/4/4.c) 5. Write a program that will read a real number from the keyboard and print the following output in one line: @@ -242,8 +242,8 @@ Smallest integer The given Lergest integer not less than number not greater than the number the number ``` -- [sadman](solutions/sadman/4/5.c) - [sharafat](solutions/sharafat/4/5.c) +- [sadman](solutions/sadman/4/5.c) 6. The total distance travelled by a vehicle in t seconds is given by ``` @@ -253,8 +253,8 @@ distance = ut + ( a t*2 ) / 2 program to evaluate the distance travelled at regular intervals of time, given the values of u and a. > The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of u and a . -- [sadman](solutions/sadman/4/6.c) - [sharafat](solutions/sharafat/4/6.c) +- [sadman](solutions/sadman/4/6.c) 7. In inventory management, the Economic Order Quantity for a single item is given by ``` @@ -266,8 +266,8 @@ TBO = sqrt ((2* setup costs) / (demand rate * holding cost per unit time)) ``` Write a program to compute EOQ and TBO, given demand rate (items per unit time), setup costs (per order), and the holding cost (per item per unit time). -- [sadman](solutions/sadman/4/7.c) - [sharafat](solutions/sharafat/4/7.c) +- [sadman](solutions/sadman/4/7.c) 8. For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency is given by @@ -276,22 +276,22 @@ Frequency = sqrt ((1 / L*C )- (R*R / 4*C*C) ``` It is desired to study the variation of this frequency with C (capacitance). Write a program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01. -- [sadman](solutions/sadman/4/8.c) - [sharafat](solutions/sharafat/4/8.c) +- [sadman](solutions/sadman/4/8.c) 9. Write a program to read a four digit integer and print the sum of its digits. Hint: Use / and % operators. -- [sadman](solutions/sadman/4/9.c) - [sharafat](solutions/sharafat/4/9.c) +- [sadman](solutions/sadman/4/9.c) 10. Given three values, write a program to read three values from keyboard and print out the largest of them without using if statement. -- [sadman](solutions/sadman/4/10.c) - [sharafat](solutions/sharafat/4/10.c) +- [sadman](solutions/sadman/4/10.c) 11. Write a program to read two integer values m and n and to decide and print whether m is a multiple of n. -- [sadman](solutions/sadman/4/11.c) - [sharafat](solutions/sharafat/4/11.c) +- [sadman](solutions/sadman/4/11.c) 12. Write a program to read three values using scanf statement and print the following results: ``` @@ -300,13 +300,13 @@ them without using if statement. (c) Largest of the three (d) Smallest of the three ``` -- [sadman](solutions/sadman/4/12.c) - [sharafat](solutions/sharafat/4/12.c) +- [sadman](solutions/sadman/4/12.c) 13. The cost of one type of mobile service is Rs. 250 plus Rs. 1.25 for each call made over and above 100 calls. Write a program to read customer codes and calls made and print the bill for each customer. -- [sadman](solutions/sadman/4/13.c) - [sharafat](solutions/sharafat/4/13.c) +- [sadman](solutions/sadman/4/13.c) 14. Write a program to print a table of sin and cos functions for the interval from 0 to 180 degrees in increments of 15 a shown here. @@ -317,8 +317,8 @@ degrees in increments of 15 a shown here. | ... | ... | ... | | ... | ... | ... | | 180 | ... | ... | -- [sadman](solutions/sadman/4/14.c) - [sharafat](solutions/sharafat/4/14.c) +- [sadman](solutions/sadman/4/14.c) 15. Write a program to compute the values of square roots and squares of the numbers 0 to 100 in steps 10 and print the output in a tabular form as shown below. @@ -327,35 +327,35 @@ degrees in increments of 15 a shown here. | ------ | ----------- | ------ | | 0 | 0 | 0 | | 100 | 10 | 10000 | -- [sadman](solutions/sadman/4/15.c) - [sharafat](solutions/sharafat/4/15.c) +- [sadman](solutions/sadman/4/15.c) 16. Write a program to illustrate the use of cast operator in a real life situation. -- [sadman](solutions/sadman/4/16.c) - [sharafat](solutions/sharafat/4/16.c) +- [sadman](solutions/sadman/4/16.c) 17. Write a C program to shift the given data by two bits to the left. -- [sadman](solutions/sadman/4/17.c) - [sharafat](solutions/sharafat/4/17.c) +- [sadman](solutions/sadman/4/17.c) 18. Write a C program to compute the value of the expression `x=a-b/3+c*2-1`. -- [sadman](solutions/sadman/4/18.c) - [sharafat](solutions/sharafat/4/18.c) +- [sadman](solutions/sadman/4/18.c) 19. Write a C program to input a date value and determine whether the entered day, month, and year values are valid. -- [sadman](solutions/sadman/4/19.c) - [sharafat](solutions/sharafat/4/19.c) +- [sadman](solutions/sadman/4/19.c) 20. Write a C program to input the sides of a triangle and determine whether the triangle is isoceles or not. -- [sadman](solutions/sadman/4/20.c) - [sharafat](solutions/sharafat/4/20.c) +- [sadman](solutions/sadman/4/20.c) 21. Write a C program that reads two numbers and performs their division. If the division is not possible, then an error messgage, ‘Division not possible’ is displayed. -- [sadman](solutions/sadman/4/21.c) - [sharafat](solutions/sharafat/4/21.c) +- [sadman](solutions/sadman/4/21.c) 22. Input the value of 4 variables a, b, c and d and compute the resultant value of following expressions: @@ -364,8 +364,8 @@ expressions: (a + b) * c / d a + (b * c) / d ``` -- [sadman](solutions/sadman/4/22.c) - [sharafat](solutions/sharafat/4/22.c) +- [sadman](solutions/sadman/4/22.c) ## Chapter 5 @@ -377,9 +377,9 @@ display the same in the following formats: PROCESSING (c) W.P. ``` +- [sharafat](solutions/sharafat/5/1.c) - [sadman](solutions/sadman/5/1.c) - [NAYEMA](solutions/NAYEMA/5/1.c) -- [sharafat](solutions/sharafat/5/1.c) 2. Write a program to read the values of x and y and print the results of the following expressions in one @@ -389,15 +389,15 @@ line: (b) (x+y) /2 (c) (x+y)(x–y) ``` +- [sharafat](solutions/sharafat/5/2.c) - [sadman](solutions/sadman/5/2.c) - [NAYEMA](solutions/NAYEMA/5/2.c) -- [sharafat](solutions/sharafat/5/2.c) 3. Write a program to read the following numbers, round them off to the nearest integers and print out the results in integer form: 35.7 50.21 – 23.73 – 46.45 +- [sharafat](solutions/sharafat/5/3.c) - [sadman](solutions/sadman/5/3.c) - [NAYEMA](solutions/NAYEMA/5/3.c) -- [sharafat](solutions/sharafat/5/3.c) 4. Write a program that reads 4 floating point values in the range, 0.0 to 20.0, and prints a horizontal bar chart to represent these values using the character * as the fill character. For the purpose of the chart, @@ -409,9 +409,9 @@ represented as follows. * * * * ``` > Note that the actual values are shown at the end of each bar. +- [sharafat](solutions/sharafat/5/4.c) - [sadman](solutions/sadman/5/4.c) - [NAYEMA](solutions/NAYEMA/5/4.c) -- [sharafat](solutions/sharafat/5/4.c) 5. Write an interactive program to demonstrate the process of multiplication. The program should ask the user to enter two two-digit integers and print the product of integers as shown below. @@ -425,9 +425,9 @@ the user to enter two two-digit integers and print the product of integers as sh Add them 1665 _______________ ``` +- [sharafat](solutions/sharafat/5/5.c) - [sadman](solutions/sadman/5/5.c) - [NAYEMA](solutions/NAYEMA/5/5.c) -- [sharafat](solutions/sharafat/5/5.c) 6. Write a program to read three integers from the keyboard using one scanf statement and output them on one line using: @@ -436,9 +436,9 @@ them on one line using: (b) only one printf with conversion specifiers, and (c) only one printf without conversion specifiers. ``` +- [sharafat](solutions/sharafat/5/6.c) - [sadman](solutions/sadman/5/6.c) - [NAYEMA](solutions/NAYEMA/5/6.c) -- [sharafat](solutions/sharafat/5/6.c) 7. Write a program that prints the value 10.45678 in exponential format with the following specifications: ``` @@ -446,9 +446,9 @@ them on one line using: (b) correct to four decimal places; and (c) correct to eight decimal places. ``` +- [sharafat](solutions/sharafat/5/7.c) - [sadman](solutions/sadman/5/7.c) - [NAYEMA](solutions/NAYEMA/5/7.c) -- [sharafat](solutions/sharafat/5/7.c) 8. Write a program to print the value 345.6789 in fixed-point format with the following specifications: ``` @@ -456,9 +456,9 @@ them on one line using: (b) correct to five decimal places; and (c) correct to zero decimal places. ``` +- [sharafat](solutions/sharafat/5/8.c) - [sadman](solutions/sadman/5/8.c) - [NAYEMA](solutions/NAYEMA/5/8.c) -- [sharafat](solutions/sharafat/5/8.c) 9. Write a program to read the name ANIL KUMAR GUPTA in three parts using the scanf statement and to display the same in the following format using the printf statement. @@ -467,9 +467,9 @@ to display the same in the following format using the printf statement. (b) A.K. GUPTA (c) GUPTA A.K. ``` +- [sharafat](solutions/sharafat/5/9.c) - [sadman](solutions/sadman/5/9.c) - [NAYEMA](solutions/NAYEMA/5/9.c) -- [sharafat](solutions/sharafat/5/9.c) 10. Write a program to read and display the following table of data. ``` @@ -478,26 +478,26 @@ to display the same in the following format using the printf statement. Motor 450 5786.70 ``` > The name and code must be left-justified and price must be right justified. +- [sharafat](solutions/sharafat/5/10.c) - [sadman](solutions/sadman/5/10.c) - [NAYEMA](solutions/NAYEMA/5/10.c) -- [sharafat](solutions/sharafat/5/10.c) 11. Write a C program to print inventory stock report using some sample data. The report should show item code, quantity and inventory location as formatted output. +- [sharafat](solutions/sharafat/5/11.c) - [sadman](solutions/sadman/5/11.c) - [NAYEMA](solutions/NAYEMA/5/11.c) -- [sharafat](solutions/sharafat/5/11.c) 12. Write a C program to display the Pascal’s triangle. +- [sharafat](solutions/sharafat/5/12.c) - [sadman](solutions/sadman/5/12.c) - [NAYEMA](solutions/NAYEMA/5/12.c) -- [sharafat](solutions/sharafat/5/12.c) 13. Write a C program to input a currency value in Dollars and display its equivalent Euro and INR amounts. You may use current exchange rate for conversion purpose. +- [sharafat](solutions/sharafat/5/13.c) - [sadman](solutions/sadman/5/13.c) - [NAYEMA](solutions/NAYEMA/5/13.c) -- [sharafat](solutions/sharafat/5/13.c) 14. Write a C program to display the following pattern. ``` @@ -512,9 +512,9 @@ INR amounts. You may use current exchange rate for conversion purpose. 15. Write a C program to input an investment amount and compute its fixed deposit cumulative return after 10 years at arate of interest of 8.75%. +- [sharafat](solutions/sharafat/5/15.c) - [sadman](solutions/sadman/5/15.c) - [NAYEMA](solutions/NAYEMA/5/15.c) -- [sharafat](solutions/sharafat/5/15.c) ## Chapter 6 @@ -526,14 +526,14 @@ NUMBER IS ODD (a) without using else option and (b) with else option. ``` -- [sadman](solutions/sadman/6/1.c) - [sharafat](solutions/sharafat/6/1.c) +- [sadman](solutions/sadman/6/1.c) 2. Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7. +- [sharafat](solutions/sharafat/6/2.c) - [sadman](solutions/sadman/6/2.c) - [NAYEMA](solutions/NAYEMA/6/2.c) -- [sharafat](solutions/sharafat/6/2.c) 3. A set of two linear equations with two unknowns x1 and x2 is given below: ``` @@ -547,8 +547,8 @@ The set has a unique solution ``` provided the denominator `ad – cb` is not equal to zero. Write a program that will read the values of constants a, b, c, d, m, and n and compute the values of x 1 and x 2. An appropriate message should be printed if ad – cb = 0. -- [NAYEMA](solutions/NAYEMA/6/3.c) - [sharafat](solutions/sharafat/6/3.c) +- [NAYEMA](solutions/NAYEMA/6/3.c) 4. Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students: @@ -563,9 +563,9 @@ students: (h) in the range 0 to 40. ``` The program should use a minimum number of if statements. +- [sharafat](solutions/sharafat/6/4.c) - [sadman](solutions/sadman/6/4.c) - [NAYEMA](solutions/NAYEMA/6/4.c) -- [sharafat](solutions/sharafat/6/4.c) 5. Admission to a professional course is subject to the following conditions: ``` @@ -577,9 +577,9 @@ The program should use a minimum number of if statements. or, Total in Mathematics and Physics >= 150 Given the marks in the three subjects, write a program to process the applications to list the eligible candidates. +- [sharafat](solutions/sharafat/6/5.c) - [sadman](solutions/sadman/6/5.c) - [NAYEMA](solutions/NAYEMA/6/5.c) -- [sharafat](solutions/sharafat/6/5.c) 6. Write a program to print a two-dimensional Square Root Table as shown below, to provide the square root of any number from 0 to 9.9. For example, the value x will give the square root of 3.2 and y the @@ -594,9 +594,9 @@ square root of 3.9. | 0.3 | | | x | | y | | ... | | | | | | | 0.9 | | | | | | +- [sharafat](solutions/sharafat/6/6.c) - [sadman](solutions/sadman/6/6.c) - [NAYEMA](solutions/NAYEMA/6/6.c) -- [sharafat](solutions/sharafat/6/6.c) 7. Shown below is a Floyd’s triangle. ``` @@ -616,9 +616,9 @@ square root of 3.9. 0 1 0 1 1 0 1 0 1 ``` +- [sharafat](solutions/sharafat/6/7.c) - [sadman](solutions/sadman/6/7.c) - [NAYEMA](solutions/NAYEMA/6/7.c) -- [sharafat](solutions/sharafat/6/7.c) 8. A cloth showroom has announced the following seasonal discounts on purchase of items: > @@ -629,14 +629,14 @@ square root of 3.9. | 101 - 200 | 5% | 7.5% | | 201 - 300 | 7.5% | 10% | | Above 300 | 10% | 15% | +- [sharafat](solutions/sharafat/6/8.c) - [sadman](solutions/sadman/6/8.c) - [NAYEMA](solutions/NAYEMA/6/8.c) -- [sharafat](solutions/sharafat/6/8.c) Write a program using switch and if statements to compute the net amount to be paid by a customer +- [sharafat](solutions/sharafat/6/9.c) - [sadman](solutions/sadman/6/9.c) - [NAYEMA](solutions/NAYEMA/6/9.c) -- [sharafat](solutions/sharafat/6/9.c) 9. Write a program that will read the value of x and evaluate the following function, ``` @@ -650,8 +650,8 @@ using, (b) else if statements, and (c) conditional operator ? : ``` -- [sadman](solutions/sadman/6/10.c) - [sharafat](solutions/sharafat/6/10.c) +- [sadman](solutions/sadman/6/10.c) 10. Write a program to compute the real roots of a quadratic equation ``` @@ -673,13 +673,13 @@ constants a, b and c and print the values of x 1 and x 2. ``` Test your program with appropriate data so that all logical paths are working as per your design. Incorporate appropriate output messages. -- [sadman](solutions/sadman/6/11.c) - [sharafat](solutions/sharafat/6/11.c) +- [sadman](solutions/sadman/6/11.c) 11. Write a program to read three integer values from the keyboard and displays the output stating that they are the sides of right-angled triangle. -- [sadman](solutions/sadman/6/12.c) - [sharafat](solutions/sharafat/6/12.c) +- [sadman](solutions/sadman/6/12.c) 12. An electricity board charges the following rates for the use of electricity: ``` @@ -691,21 +691,21 @@ All users are charged a minimum of Rs. 100 as meter charge. If the total amount then an additional surcharge of 15% of total amount is charged. Write a program to read the names of users and number of units consumed and print out the charges with names. -- [sadman](solutions/sadman/6/13.c) - [sharafat](solutions/sharafat/6/13.c) +- [sadman](solutions/sadman/6/13.c) 13. Write a program to compute and display the sum of all integers that are divisible by 6 but not divisible by 4 and lie between 0 and 100. The program should also count and display the number of such values. -- [sadman](solutions/sadman/6/14.c) - [sharafat](solutions/sharafat/6/14.c) +- [sadman](solutions/sadman/6/14.c) 14. Write an interactive program that could read a positive integer number and decide whether the number is a prime number and display the output accordingly. Modify the program to count all the prime numbers that lie between 100 and 200. > NOTE : A prime number is a positive integer that is divisible only by 1 or by itself. -- [sadman](solutions/sadman/6/15.c) - [sharafat](solutions/sharafat/6/15.c) +- [sadman](solutions/sadman/6/15.c) 15. Write a program to read a double-type value x that represents angle in radians and a character-type variable T that represents the type of trigonometric function and display the value of @@ -715,13 +715,13 @@ variable T that represents the type of trigonometric function and display the va (c) tan (x), if t or T is assigned to T ``` using, (i) if......else statement , and (ii) switch statement. -- [sadman](solutions/sadman/6/16.c) - [sharafat](solutions/sharafat/6/16.c) +- [sadman](solutions/sadman/6/16.c) 16. Write a C program to input the numeric week day value (starting from Monday as 1) and display the corresponding name of the week day. -- [sadman](solutions/sadman/6/17.c) - [sharafat](solutions/sharafat/6/17.c) +- [sadman](solutions/sadman/6/17.c) 17. Write a C program to input two numbers a and b and display whether ``` @@ -729,8 +729,8 @@ corresponding name of the week day. (b) b is greater than b (c) or, a and b are equal ``` -- [sadman](solutions/sadman/6/18.c) - [sharafat](solutions/sharafat/6/18.c) +- [sadman](solutions/sadman/6/18.c) 18. Write a C program to input the total percentage of marks of a student and display its Division using below rules: @@ -739,14 +739,14 @@ below rules: (b) Greater than or equal to 60 percent and less than 80 per cent - “Second Division” (c) Less than 60 percent - “Third Division" ``` -- [sadman](solutions/sadman/6/19.c) - [sharafat](solutions/sharafat/6/19.c) +- [sadman](solutions/sadman/6/19.c) 19. Using Switch case block, input the name of the month from the user and display the corresponding number of days in that month. +- [sharafat](solutions/sharafat/6/20.c) - [sadman](solutions/sadman/6/20.c) - [NAYEMA](solutions/NAYEMA/6/20.c) -- [sharafat](solutions/sharafat/6/20.c) 20. Write a C program that inputs a string and counts the number of capital and small alphabets in that string. @@ -763,12 +763,12 @@ should be written as ``` > ( Hint: Use modulus operator to extract the last digit and the integer division by 10 to get the n–1 digit number from the n digit number.) -- [sadman](solutions/sadman/7/1.c) - [sharafat](solutions/sharafat/7/1.c) +- [sadman](solutions/sadman/7/1.c) 2. Write a program to compute the sum of the digits of a given integer number. -- [sadman](solutions/sadman/7/2.c) - [sharafat](solutions/sharafat/7/2.c) +- [sadman](solutions/sadman/7/2.c) 3. The numbers in the sequence ``` @@ -777,8 +777,8 @@ digit number from the n digit number.) are called Fibonacci numbers. Write a program using a do....while loop to calculate and print the first m Fibonacci numbers. > ( Hint: After the first two numbers in the series, each number is the sum of the two preceding numbers.) -- [sadman](solutions/sadman/7/3.c) - [sharafat](solutions/sharafat/7/3.c) +- [sadman](solutions/sadman/7/3.c) 4. Write a program to evaluate the following investment equation ``` @@ -799,8 +799,8 @@ be recursively written as ``` That is, the value of money at the end of first year becomes the principal amount for the next year and so on.) -- [sadman](solutions/sadman/7/4.c) - [sharafat](solutions/sharafat/7/4.c) +- [sadman](solutions/sadman/7/4.c) 5. Write programs to print the following outputs using for loops. ``` @@ -811,18 +811,18 @@ so on.) 4 4 4 4 * * 5 5 5 5 5 * ``` -- [sadman](solutions/sadman/7/5.c) - [sharafat](solutions/sharafat/7/5.c) +- [sadman](solutions/sadman/7/5.c) 6. Write a program to read the age of 100 persons and count the number of persons in the age group 50 to 60. Use for and continue statements. -- [sadman](solutions/sadman/7/6.c) - [sharafat](solutions/sharafat/7/6.c) +- [sadman](solutions/sadman/7/6.c) 7. Rewrite the program of case study 7.4 (plotting of two curves) using else...if constructs instead of continue statements. -- [sadman](solutions/sadman/7/7.c) - [sharafat](solutions/sharafat/7/7.c) +- [sadman](solutions/sadman/7/7.c) 8. Write a program to print a table of values of the function ``` @@ -841,8 +841,8 @@ for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as foll | . | | | | | | | . | | | | | | |9.0| | | | | | -- [sadman](solutions/sadman/7/8.c) - [sharafat](solutions/sharafat/7/8.c) +- [sadman](solutions/sadman/7/8.c) 9. Write a program using for and if statement to display the capital letter S in a grid of 15 rows and 18 columns as shown below. @@ -864,8 +864,8 @@ for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as foll ***-----------**** **------------**** ``` -- [sadman](solutions/sadman/7/9.c) - [sharafat](solutions/sharafat/7/9.c) +- [sadman](solutions/sadman/7/9.c) 10. Write a program to compute the value of Euler’s number e, that is used as the base of natural logarithms. Use the following formula. @@ -874,8 +874,8 @@ logarithms. Use the following formula. ``` Use a suitable loop construct. The loop must terminate when the difference between two successive values of e is less than 0.00001. -- [sadman](solutions/sadman/7/10.c) - [sharafat](solutions/sharafat/7/10.c) +- [sadman](solutions/sadman/7/10.c) 11. Write programs to evaluate the following functions to 0.0001% accuracy. ``` @@ -883,8 +883,8 @@ successive values of e is less than 0.00001. (b) cosx = 1 – x 2 /2! + x 4 /4! – x 6 /6! + . . . . . (c) SUM = 1 + (1/2) 2 + (1/3) 3 + (1/4) 4 + … … ``` -- [sadman](solutions/sadman/7/11.c) - [sharafat](solutions/sharafat/7/11.c) +- [sadman](solutions/sadman/7/11.c) 12. The present value (popularly known as book value) of an item is given by the relationship. ``` @@ -898,8 +898,8 @@ successive values of e is less than 0.00001. If P is considered the scrap value at the end of useful life of the item, write a program to compute the useful life in years given the original cost, depreciation rate, and the scrap value. The program should request the user to input the data interactively. -- [sadman](solutions/sadman/7/12.c) - [sharafat](solutions/sharafat/7/12.c) +- [sadman](solutions/sadman/7/12.c) 13. Write a program to print a square of size 5 by using the character N as shown below: ``` @@ -911,16 +911,16 @@ The program should request the user to input the data interactively. n n n n n n n n n n ``` > n is used insted of S in the above figure LOL. -- [sadman](solutions/sadman/7/13.c) - [sharafat](solutions/sharafat/7/13.c) +- [sadman](solutions/sadman/7/13.c) 14. Write a program to graph the function ``` y = sin (x) ``` in the interval 0 to 180 degrees in steps of 15 degrees. Use the concepts discussed in the Case Study 4 in Chapter 7. -- [sadman](solutions/sadman/7/14.c) - [sharafat](solutions/sharafat/7/14.c) +- [sadman](solutions/sadman/7/14.c) 15. Modify the program of Exercise 7.16 to print the character S instead of N at the center of the square as shown below. ``` @@ -931,17 +931,17 @@ in the interval 0 to 180 degrees in steps of 15 degrees. Use the concepts discus n n n n n ``` > n is used insted of S in the above figure LOL. -- [sadman](solutions/sadman/7/15.c) - [sharafat](solutions/sharafat/7/15.c) +- [sadman](solutions/sadman/7/15.c) 16. Given a set of 10 two-digit integers containing both positive and negative values, write a program using for loop to compute the sum of all positive values and print the sum and the number of values added. The program should use scanf to read the values and terminate when the sum exceeds 999. Do not use goto statement. -- [sadman](solutions/sadman/7/16.c) - [sharafat](solutions/sharafat/7/16.c) +- [sadman](solutions/sadman/7/16.c) 17. Write a C program to display a coloured line. -- [sadman](solutions/sadman/7/17.c) - [sharafat](solutions/sharafat/7/17.c) +- [sadman](solutions/sadman/7/17.c) 18. Write a C program to display the following pattern. ``` @@ -951,8 +951,8 @@ The program should use scanf to read the values and terminate when the sum excee C D E F 5 6 7 8 9 ``` -- [sadman](solutions/sadman/7/18.c) - [sharafat](solutions/sharafat/7/18.c) +- [sadman](solutions/sadman/7/18.c) 19. Write a C program to display the following pattern: ``` @@ -962,8 +962,8 @@ The program should use scanf to read the values and terminate when the sum excee 1 2 1 1 ``` -- [sadman](solutions/sadman/7/19.c) - [sharafat](solutions/sharafat/7/19.c) +- [sadman](solutions/sadman/7/19.c) 20. Write a C program to display the following pattern: ``` @@ -986,8 +986,8 @@ y = mx + c ``` and the values of m and c are given y the following equations: > All summations are from 1 to n. -- [sadman](solutions/sadman/8/1.c) - [sharafat](solutions/sharafat/8/1.c) +- [sadman](solutions/sadman/8/1.c) 2. The daily maximum temperatures recorded in 10 cities during the month of January (for all 31 days) have been tabulated. Write a program to read the table elements into a two-dimensional array temperature , and to find the city and day corresponding to @@ -995,12 +995,12 @@ Write a program to read the table elements into a two-dimensional array temperat (a) the highest temperature and (b) the lowest temperature. ``` -- [sadman](solutions/sadman/8/2.c) - [sharafat](solutions/sharafat/8/2.c) +- [sadman](solutions/sadman/8/2.c) 3. An election is contested by 5 candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count . In case, a number read is outside the range 1 to 5, the ballot should be considered as a ‘spoilt ballot’ and the program should also count the number of spoilt ballots. -- [sadman](solutions/sadman/8/3.c) - [sharafat](solutions/sharafat/8/3.c) +- [sadman](solutions/sadman/8/3.c) 4. The following set of numbers is popularly known as Pascal’s triangle. ``` @@ -1017,8 +1017,8 @@ If we denote rows by i and columns by j, then any element p ij = p i–1 ,j–1 + p i–1 ,j ``` Write a program to calculate the elements of the Pascal triangle for 10 rows and print the results. -- [sadman](solutions/sadman/8/4.c) - [sharafat](solutions/sharafat/8/4.c) +- [sadman](solutions/sadman/8/4.c) 5. The annual examination results of 100 students are tabulated as follows: > @@ -1034,12 +1034,12 @@ Write a program to read the data and determine the following: (b) The highest marks in each subject and the Roll No. of the student who secured it. (c) The student who obtained the highest total marks. ``` -- [sadman](solutions/sadman/8/5.c) - [sharafat](solutions/sharafat/8/5.c) +- [sadman](solutions/sadman/8/5.c) 6. Given are two one-dimensional arrays A and B which are sorted in ascending order. Write a program to merge them into a single sorted array that contains every item from arrays A and B, in ascending order. -- [sadman](solutions/sadman/8/6.c) - [sharafat](solutions/sharafat/8/6.c) +- [sadman](solutions/sadman/8/6.c) 7. Two matrices that have the same number of rows and columns can be multiplied to produce a third matrix. Consider the following two matrices. The product of A and B is a third matrix C of size n¥ n where each element of C is given by the following equation. @@ -1047,8 +1047,8 @@ The product of A and B is a third matrix C of size n¥ n where each element of C multiplied_matrix[i][j] += first_matrix[i][k] * second_matrix[k][j]; ``` Write a program that will read the values of elements of A and B and produce the product matrix C. -- [sadman](solutions/sadman/8/7.c) - [sharafat](solutions/sharafat/8/7.c) +- [sadman](solutions/sadman/8/7.c) 8. Write a program that fills a five-by-five matrix as follows: ``` @@ -1057,12 +1057,12 @@ Write a program that will read the values of elements of A and B and produce the - Right to left diagonal with zeros Display the contents of the matrix using not more than two printf statements. ``` -- [sadman](solutions/sadman/8/8.c) - [sharafat](solutions/sharafat/8/8.c) +- [sadman](solutions/sadman/8/8.c) 9. Selection sort is based on the following idea: Selecting the largest array element and swapping it with the last array element leaves an unsorted list whose size is 1 less than the size of the original list. If we repeat this step again on the unsorted list we will have an ordered list of size 2 and an unordered list size n–2 . When we repeat this until the size of the unsorted list becomes one, the result will be a sorted list. Write a program to implement this algorithm. -- [sadman](solutions/sadman/8/9.c) - [sharafat](solutions/sharafat/8/9.c) +- [sadman](solutions/sadman/8/9.c) 10. Develop a program to implement the binary search algorithm. This technique compares the search key value with the value of the element that is midway in a “sorted” list. Then; ``` @@ -1072,20 +1072,20 @@ Display the contents of the matrix using not more than two printf statements. ``` Repeat this “divide-and-conquer” strategy until we have a match. If the list is reduced to one nonmatching element, then the list does not contain the key value. Use the sorted list created in Exercise 8.9 or use any other sorted list. -- [sadman](solutions/sadman/8/10.c) - [sharafat](solutions/sharafat/8/10.c) +- [sadman](solutions/sadman/8/10.c) 11. Write a program that will compute the length of a given character string. -- [sadman](solutions/sadman/8/11.c) - [sharafat](solutions/sharafat/8/11.c) +- [sadman](solutions/sadman/8/11.c) 12. Write a program that will count the number occurrences of a specified character in a given line of text. Test your program. -- [sadman](solutions/sadman/8/12.c) - [sharafat](solutions/sharafat/8/12.c) +- [sadman](solutions/sadman/8/12.c) 13. Write a program to read a matrix of size m ¥ n and print its transpose. -- [sadman](solutions/sadman/8/13.c) - [sharafat](solutions/sharafat/8/13.c) +- [sadman](solutions/sadman/8/13.c) 14. Every book published by international publishers should carry an International Standard Book Number (ISBN). It is a 10 character 4 part number as shown below. ``` @@ -1096,42 +1096,42 @@ The first part denotes the region, the second represents publisher, the third id Sum = (1 × first digit) + (2 × second digit) + (3 ×third digit) + - - - - + (9 × ninth digit). ``` Check digit is the remainder when sum is divided by 11. Write a program that reads a given ISBN number and checks whether it represents a valid ISBN. -- [sadman](solutions/sadman/8/14.c) - [sharafat](solutions/sharafat/8/14.c) +- [sadman](solutions/sadman/8/14.c) 15. Write a program to read two matrices A and B and print the following: ``` (a) A + B; and (b) A – B. ``` -- [sadman](solutions/sadman/8/15.c) - [sharafat](solutions/sharafat/8/15.c) +- [sadman](solutions/sadman/8/15.c) 16. Write a C program to compute the sum of elements of two one-dimensional arrays and store the corresponding result in another array. -- [sadman](solutions/sadman/8/16.c) - [sharafat](solutions/sharafat/8/16.c) +- [sadman](solutions/sadman/8/16.c) 17. Write a C program to identify and count all the odd numbers in an array and calculate their sum. -- [sadman](solutions/sadman/8/17.c) - [sharafat](solutions/sharafat/8/17.c) +- [sadman](solutions/sadman/8/17.c) 18. Write a C program to input an amount in Indian currency and deduce the minimum currency denomination for that amount. -- [sadman](solutions/sadman/8/18.c) - [sharafat](solutions/sharafat/8/18.c) +- [sadman](solutions/sadman/8/18.c) 19. Write a C program to input a Roman number and compute its decimal equivalent. - [sharafat](solutions/sharafat/8/19.c) 20. Write a C program to input two NXN matrices and deduce their sum and product. -- [sadman](solutions/sadman/8/20.c) - [sharafat](solutions/sharafat/8/20.c) +- [sadman](solutions/sadman/8/20.c) ## Chapter 9 1. Write a program, which reads your name from the keyboard and outputs a list of ASCII codes, which represent your name. +- [sharafat](solutions/sharafat/9/1.c) - [sadman](solutions/sadman/9/1.c) - [NAYEMA](solutions/NAYEMA/9/1.c) -- [sharafat](solutions/sharafat/9/1.c) 2. Write a program to do the following: ``` @@ -1141,29 +1141,29 @@ Check digit is the remainder when sum is divided by 11. Write a program that rea (d) To output the message ‘try again’, if the answer is wrong. (e) To display the correct answer when the answer is wrong even at the third attempt and stop. ``` +- [sharafat](solutions/sharafat/9/2.c) - [sadman](solutions/sadman/9/2.c) - [NAYEMA](solutions/NAYEMA/9/2.c) -- [sharafat](solutions/sharafat/9/2.c) 3. Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character. +- [sharafat](solutions/sharafat/9/3.c) - [sadman](solutions/sadman/9/3.c) - [NAYEMA](solutions/NAYEMA/9/3.c) -- [sharafat](solutions/sharafat/9/3.c) 4. Write a program which will read a text and count all occurrences of a particular word. +- [sharafat](solutions/sharafat/9/4.c) - [sadman](solutions/sadman/9/4.c) - [NAYEMA](solutions/NAYEMA/9/4.c) -- [sharafat](solutions/sharafat/9/4.c) 5. Write a program which will read a string and rewrite it in the alphabetical order. For example, the word STRING should be written as GINRST. +- [sharafat](solutions/sharafat/9/5.c) - [sadman](solutions/sadman/9/5.c) - [NAYEMA](solutions/NAYEMA/9/5.c) -- [sharafat](solutions/sharafat/9/5.c) 6. Write a program to replace a particular word by another word in a given string. For example, the word “PASCAL” should be replaced by “C” in the text “It is good to program in PASCAL language.” +- [sharafat](solutions/sharafat/9/6.c) - [sadman](solutions/sadman/9/6.c) - [NAYEMA](solutions/NAYEMA/9/6.c) -- [sharafat](solutions/sharafat/9/6.c) 7. A Maruti car dealer maintains a record of sales of various vehicles in the following form: @@ -1179,8 +1179,8 @@ Write a program to read this data into a table of strings and output the details - [sadman](solutions/sadman/9/7.c) 8. Write a program that reads a string from the keyboard and determines whether the string is a palindrome or not. (A string is a palindrome if it can be read from left and right with the same meaning. For example, Madam and Anna are palindrome strings. Ignore capitalization). -- [sadman](solutions/sadman/9/8.c) - [sharafat](solutions/sharafat/9/8.c) +- [sadman](solutions/sadman/9/8.c) 9. Write program that reads the cost of an item in the form RRRR.PP (Where RRRR denotes Rupees and PP denotes Paise) and converts the value to a string of words that expresses the numeric value in words. For example, if we input 125.75, the output should be “ONE HUNDRED TWENTY FIVE AND PAISE SEVENTY FIVE”. @@ -1199,25 +1199,25 @@ and produce the following output list: (b) List sorted on roll numbers. (c) List sorted on marks (rank-wise list) ``` -- [sadman](solutions/sadman/9/10.c) - [sharafat](solutions/sharafat/9/10.c) +- [sadman](solutions/sadman/9/10.c) 11. Write a program to read two strings and compare them using the function strncmp( ) and print a message that the first string is equal, less, or greater than the second one. -- [sadman](solutions/sadman/9/11.c) - [sharafat](solutions/sharafat/9/11.c) +- [sadman](solutions/sadman/9/11.c) 12. Write a program to read a line of text from the keyboard and print out the number of occurrences of a given substring using the function strstr ( ). -- [sadman](solutions/sadman/9/12.c) - [sharafat](solutions/sharafat/9/12.c) +- [sadman](solutions/sadman/9/12.c) 13. Write a program that will copy m consecutive characters from a string s1 beginning at position n into another string s2. -- [sadman](solutions/sadman/9/13.c) - [sharafat](solutions/sharafat/9/13.c) +- [sadman](solutions/sadman/9/13.c) 14. Write a program to create a directory of students with roll numbers. The program should display the roll number for a specified name and vice-versa. -- [sadman](solutions/sadman/9/14.c) - [sharafat](solutions/sharafat/9/14.c) +- [sadman](solutions/sadman/9/14.c) 15. Given a string ``` @@ -1231,34 +1231,34 @@ Write a program that displays the following: 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5 ``` -- [sadman](solutions/sadman/9/15.c) - [sharafat](solutions/sharafat/9/15.c) +- [sadman](solutions/sadman/9/15.c) 16. Write a C program to compare two strings without using any string function. -- [sadman](solutions/sadman/9/16.c) - [sharafat](solutions/sharafat/9/16.c) +- [sadman](solutions/sadman/9/16.c) 17. Write a C program to find the largest and smallest sized word in a string. -- [sadman](solutions/sadman/9/17.c) - [sharafat](solutions/sharafat/9/17.c) +- [sadman](solutions/sadman/9/17.c) 18. Write a C program to replace all the white spaces in a string with double white spaces. -- [sadman](solutions/sadman/9/18.c) - [sharafat](solutions/sharafat/9/18.c) +- [sadman](solutions/sadman/9/18.c) 19. Write a C program to enter multiple strings and display them in lexicographical order. -- [sadman](solutions/sadman/9/19.c) - [sharafat](solutions/sharafat/9/19.c) +- [sadman](solutions/sadman/9/19.c) 20. Write a C program to concatenate two strings without using any string function. -- [sadman](solutions/sadman/9/20.c) - [sharafat](solutions/sharafat/9/20.c) +- [sadman](solutions/sadman/9/20.c) ## Chapter 10 1. Write a function exchange to interchange the values of two variables, say x and y. Illustrate the use of this function, in a calling function. Assume that x and y are defined as global variables. -- [sadman](solutions/sadman/10/1.c) - [Hridoy](solutions/Hridoy/10/1.c) +- [sadman](solutions/sadman/10/1.c) 2. Write a function space(x) that can be used to provide a space of x positions between two output numbers. Demonstrate its application. - [sadman](solutions/sadman/10/2.c) From 2df2898e1b231d9ae2f8524baa32a308cbede711 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 10 Jul 2023 01:27:41 +0000 Subject: [PATCH 04/19] updated logs --- README.md | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 7af1917..a147e57 100644 --- a/README.md +++ b/README.md @@ -377,9 +377,9 @@ display the same in the following formats: PROCESSING (c) W.P. ``` +- [NAYEMA](solutions/NAYEMA/5/1.c) - [sharafat](solutions/sharafat/5/1.c) - [sadman](solutions/sadman/5/1.c) -- [NAYEMA](solutions/NAYEMA/5/1.c) 2. Write a program to read the values of x and y and print the results of the following expressions in one @@ -389,15 +389,15 @@ line: (b) (x+y) /2 (c) (x+y)(x–y) ``` +- [NAYEMA](solutions/NAYEMA/5/2.c) - [sharafat](solutions/sharafat/5/2.c) - [sadman](solutions/sadman/5/2.c) -- [NAYEMA](solutions/NAYEMA/5/2.c) 3. Write a program to read the following numbers, round them off to the nearest integers and print out the results in integer form: 35.7 50.21 – 23.73 – 46.45 +- [NAYEMA](solutions/NAYEMA/5/3.c) - [sharafat](solutions/sharafat/5/3.c) - [sadman](solutions/sadman/5/3.c) -- [NAYEMA](solutions/NAYEMA/5/3.c) 4. Write a program that reads 4 floating point values in the range, 0.0 to 20.0, and prints a horizontal bar chart to represent these values using the character * as the fill character. For the purpose of the chart, @@ -409,9 +409,9 @@ represented as follows. * * * * ``` > Note that the actual values are shown at the end of each bar. +- [NAYEMA](solutions/NAYEMA/5/4.c) - [sharafat](solutions/sharafat/5/4.c) - [sadman](solutions/sadman/5/4.c) -- [NAYEMA](solutions/NAYEMA/5/4.c) 5. Write an interactive program to demonstrate the process of multiplication. The program should ask the user to enter two two-digit integers and print the product of integers as shown below. @@ -425,9 +425,9 @@ the user to enter two two-digit integers and print the product of integers as sh Add them 1665 _______________ ``` +- [NAYEMA](solutions/NAYEMA/5/5.c) - [sharafat](solutions/sharafat/5/5.c) - [sadman](solutions/sadman/5/5.c) -- [NAYEMA](solutions/NAYEMA/5/5.c) 6. Write a program to read three integers from the keyboard using one scanf statement and output them on one line using: @@ -436,9 +436,9 @@ them on one line using: (b) only one printf with conversion specifiers, and (c) only one printf without conversion specifiers. ``` +- [NAYEMA](solutions/NAYEMA/5/6.c) - [sharafat](solutions/sharafat/5/6.c) - [sadman](solutions/sadman/5/6.c) -- [NAYEMA](solutions/NAYEMA/5/6.c) 7. Write a program that prints the value 10.45678 in exponential format with the following specifications: ``` @@ -446,9 +446,9 @@ them on one line using: (b) correct to four decimal places; and (c) correct to eight decimal places. ``` +- [NAYEMA](solutions/NAYEMA/5/7.c) - [sharafat](solutions/sharafat/5/7.c) - [sadman](solutions/sadman/5/7.c) -- [NAYEMA](solutions/NAYEMA/5/7.c) 8. Write a program to print the value 345.6789 in fixed-point format with the following specifications: ``` @@ -456,9 +456,9 @@ them on one line using: (b) correct to five decimal places; and (c) correct to zero decimal places. ``` +- [NAYEMA](solutions/NAYEMA/5/8.c) - [sharafat](solutions/sharafat/5/8.c) - [sadman](solutions/sadman/5/8.c) -- [NAYEMA](solutions/NAYEMA/5/8.c) 9. Write a program to read the name ANIL KUMAR GUPTA in three parts using the scanf statement and to display the same in the following format using the printf statement. @@ -467,9 +467,9 @@ to display the same in the following format using the printf statement. (b) A.K. GUPTA (c) GUPTA A.K. ``` +- [NAYEMA](solutions/NAYEMA/5/9.c) - [sharafat](solutions/sharafat/5/9.c) - [sadman](solutions/sadman/5/9.c) -- [NAYEMA](solutions/NAYEMA/5/9.c) 10. Write a program to read and display the following table of data. ``` @@ -478,26 +478,26 @@ to display the same in the following format using the printf statement. Motor 450 5786.70 ``` > The name and code must be left-justified and price must be right justified. +- [NAYEMA](solutions/NAYEMA/5/10.c) - [sharafat](solutions/sharafat/5/10.c) - [sadman](solutions/sadman/5/10.c) -- [NAYEMA](solutions/NAYEMA/5/10.c) 11. Write a C program to print inventory stock report using some sample data. The report should show item code, quantity and inventory location as formatted output. +- [NAYEMA](solutions/NAYEMA/5/11.c) - [sharafat](solutions/sharafat/5/11.c) - [sadman](solutions/sadman/5/11.c) -- [NAYEMA](solutions/NAYEMA/5/11.c) 12. Write a C program to display the Pascal’s triangle. +- [NAYEMA](solutions/NAYEMA/5/12.c) - [sharafat](solutions/sharafat/5/12.c) - [sadman](solutions/sadman/5/12.c) -- [NAYEMA](solutions/NAYEMA/5/12.c) 13. Write a C program to input a currency value in Dollars and display its equivalent Euro and INR amounts. You may use current exchange rate for conversion purpose. +- [NAYEMA](solutions/NAYEMA/5/13.c) - [sharafat](solutions/sharafat/5/13.c) - [sadman](solutions/sadman/5/13.c) -- [NAYEMA](solutions/NAYEMA/5/13.c) 14. Write a C program to display the following pattern. ``` @@ -507,14 +507,14 @@ INR amounts. You may use current exchange rate for conversion purpose. 2 1 1 ``` -- [sadman](solutions/sadman/5/14.c) - [NAYEMA](solutions/NAYEMA/5/14.c) +- [sadman](solutions/sadman/5/14.c) 15. Write a C program to input an investment amount and compute its fixed deposit cumulative return after 10 years at arate of interest of 8.75%. +- [NAYEMA](solutions/NAYEMA/5/15.c) - [sharafat](solutions/sharafat/5/15.c) - [sadman](solutions/sadman/5/15.c) -- [NAYEMA](solutions/NAYEMA/5/15.c) ## Chapter 6 @@ -531,9 +531,9 @@ NUMBER IS ODD 2. Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7. +- [NAYEMA](solutions/NAYEMA/6/2.c) - [sharafat](solutions/sharafat/6/2.c) - [sadman](solutions/sadman/6/2.c) -- [NAYEMA](solutions/NAYEMA/6/2.c) 3. A set of two linear equations with two unknowns x1 and x2 is given below: ``` @@ -547,8 +547,8 @@ The set has a unique solution ``` provided the denominator `ad – cb` is not equal to zero. Write a program that will read the values of constants a, b, c, d, m, and n and compute the values of x 1 and x 2. An appropriate message should be printed if ad – cb = 0. -- [sharafat](solutions/sharafat/6/3.c) - [NAYEMA](solutions/NAYEMA/6/3.c) +- [sharafat](solutions/sharafat/6/3.c) 4. Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students: @@ -563,9 +563,9 @@ students: (h) in the range 0 to 40. ``` The program should use a minimum number of if statements. +- [NAYEMA](solutions/NAYEMA/6/4.c) - [sharafat](solutions/sharafat/6/4.c) - [sadman](solutions/sadman/6/4.c) -- [NAYEMA](solutions/NAYEMA/6/4.c) 5. Admission to a professional course is subject to the following conditions: ``` @@ -577,9 +577,9 @@ The program should use a minimum number of if statements. or, Total in Mathematics and Physics >= 150 Given the marks in the three subjects, write a program to process the applications to list the eligible candidates. +- [NAYEMA](solutions/NAYEMA/6/5.c) - [sharafat](solutions/sharafat/6/5.c) - [sadman](solutions/sadman/6/5.c) -- [NAYEMA](solutions/NAYEMA/6/5.c) 6. Write a program to print a two-dimensional Square Root Table as shown below, to provide the square root of any number from 0 to 9.9. For example, the value x will give the square root of 3.2 and y the @@ -594,9 +594,9 @@ square root of 3.9. | 0.3 | | | x | | y | | ... | | | | | | | 0.9 | | | | | | +- [NAYEMA](solutions/NAYEMA/6/6.c) - [sharafat](solutions/sharafat/6/6.c) - [sadman](solutions/sadman/6/6.c) -- [NAYEMA](solutions/NAYEMA/6/6.c) 7. Shown below is a Floyd’s triangle. ``` @@ -616,9 +616,9 @@ square root of 3.9. 0 1 0 1 1 0 1 0 1 ``` +- [NAYEMA](solutions/NAYEMA/6/7.c) - [sharafat](solutions/sharafat/6/7.c) - [sadman](solutions/sadman/6/7.c) -- [NAYEMA](solutions/NAYEMA/6/7.c) 8. A cloth showroom has announced the following seasonal discounts on purchase of items: > @@ -629,14 +629,14 @@ square root of 3.9. | 101 - 200 | 5% | 7.5% | | 201 - 300 | 7.5% | 10% | | Above 300 | 10% | 15% | +- [NAYEMA](solutions/NAYEMA/6/8.c) - [sharafat](solutions/sharafat/6/8.c) - [sadman](solutions/sadman/6/8.c) -- [NAYEMA](solutions/NAYEMA/6/8.c) Write a program using switch and if statements to compute the net amount to be paid by a customer +- [NAYEMA](solutions/NAYEMA/6/9.c) - [sharafat](solutions/sharafat/6/9.c) - [sadman](solutions/sadman/6/9.c) -- [NAYEMA](solutions/NAYEMA/6/9.c) 9. Write a program that will read the value of x and evaluate the following function, ``` @@ -744,9 +744,9 @@ below rules: 19. Using Switch case block, input the name of the month from the user and display the corresponding number of days in that month. +- [NAYEMA](solutions/NAYEMA/6/20.c) - [sharafat](solutions/sharafat/6/20.c) - [sadman](solutions/sadman/6/20.c) -- [NAYEMA](solutions/NAYEMA/6/20.c) 20. Write a C program that inputs a string and counts the number of capital and small alphabets in that string. @@ -1129,9 +1129,9 @@ Check digit is the remainder when sum is divided by 11. Write a program that rea ## Chapter 9 1. Write a program, which reads your name from the keyboard and outputs a list of ASCII codes, which represent your name. +- [NAYEMA](solutions/NAYEMA/9/1.c) - [sharafat](solutions/sharafat/9/1.c) - [sadman](solutions/sadman/9/1.c) -- [NAYEMA](solutions/NAYEMA/9/1.c) 2. Write a program to do the following: ``` @@ -1141,29 +1141,29 @@ Check digit is the remainder when sum is divided by 11. Write a program that rea (d) To output the message ‘try again’, if the answer is wrong. (e) To display the correct answer when the answer is wrong even at the third attempt and stop. ``` +- [NAYEMA](solutions/NAYEMA/9/2.c) - [sharafat](solutions/sharafat/9/2.c) - [sadman](solutions/sadman/9/2.c) -- [NAYEMA](solutions/NAYEMA/9/2.c) 3. Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character. +- [NAYEMA](solutions/NAYEMA/9/3.c) - [sharafat](solutions/sharafat/9/3.c) - [sadman](solutions/sadman/9/3.c) -- [NAYEMA](solutions/NAYEMA/9/3.c) 4. Write a program which will read a text and count all occurrences of a particular word. +- [NAYEMA](solutions/NAYEMA/9/4.c) - [sharafat](solutions/sharafat/9/4.c) - [sadman](solutions/sadman/9/4.c) -- [NAYEMA](solutions/NAYEMA/9/4.c) 5. Write a program which will read a string and rewrite it in the alphabetical order. For example, the word STRING should be written as GINRST. +- [NAYEMA](solutions/NAYEMA/9/5.c) - [sharafat](solutions/sharafat/9/5.c) - [sadman](solutions/sadman/9/5.c) -- [NAYEMA](solutions/NAYEMA/9/5.c) 6. Write a program to replace a particular word by another word in a given string. For example, the word “PASCAL” should be replaced by “C” in the text “It is good to program in PASCAL language.” +- [NAYEMA](solutions/NAYEMA/9/6.c) - [sharafat](solutions/sharafat/9/6.c) - [sadman](solutions/sadman/9/6.c) -- [NAYEMA](solutions/NAYEMA/9/6.c) 7. A Maruti car dealer maintains a record of sales of various vehicles in the following form: @@ -1257,8 +1257,8 @@ Write a program that displays the following: ## Chapter 10 1. Write a function exchange to interchange the values of two variables, say x and y. Illustrate the use of this function, in a calling function. Assume that x and y are defined as global variables. -- [Hridoy](solutions/Hridoy/10/1.c) - [sadman](solutions/sadman/10/1.c) +- [Hridoy](solutions/Hridoy/10/1.c) 2. Write a function space(x) that can be used to provide a space of x positions between two output numbers. Demonstrate its application. - [sadman](solutions/sadman/10/2.c) From 994b9f07d216a97569bfde27e6a5bf9e2a310d71 Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:27:34 +0600 Subject: [PATCH 05/19] 10 | 1 | sharafat --- solutions/sharafat/10/1.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/sharafat/10/1.c diff --git a/solutions/sharafat/10/1.c b/solutions/sharafat/10/1.c new file mode 100644 index 0000000..f145b66 --- /dev/null +++ b/solutions/sharafat/10/1.c @@ -0,0 +1,18 @@ +#include + +int a = 10, b = 20; + +void swap (void) +{ + b = a + b ; + a = b - a ; + b = b - a ; +} + +int main() +{ + printf("Before swap: a = %d, b = %d\n", a, b); + swap(); + printf("After swap: a = %d, b = %d\n", a, b); + return 0; +} \ No newline at end of file From af6ddec558b92c45d8ab5cf6b59b816b72328c98 Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:27:49 +0600 Subject: [PATCH 06/19] 10 | 2 | sharafat --- solutions/sharafat/10/2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 solutions/sharafat/10/2.c diff --git a/solutions/sharafat/10/2.c b/solutions/sharafat/10/2.c new file mode 100644 index 0000000..84d76ed --- /dev/null +++ b/solutions/sharafat/10/2.c @@ -0,0 +1,14 @@ +#include + +void space(int x) { + for (int i = 0; i < x; i++) { + printf(" "); + } +} + +int main() { + printf("123"); + space(3); + printf("456\n"); + return 0; +} From a9dbcd0db28aa335aa16f8f59c16a143997793cb Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:27:58 +0600 Subject: [PATCH 07/19] 3 --- solutions/sharafat/10/3.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 solutions/sharafat/10/3.c diff --git a/solutions/sharafat/10/3.c b/solutions/sharafat/10/3.c new file mode 100644 index 0000000..feb0ffc --- /dev/null +++ b/solutions/sharafat/10/3.c @@ -0,0 +1,27 @@ +#include +#include + +int factorial(int n) +{ + if (n == 1) + return 1; + else + return n * factorial(n - 1); +} + +float evaluate(int x, int n, int i) +{ + if (n >= 10) + return 0; + else if (i % 2 == 0) + return -pow(x, n) / factorial(n) + evaluate(x, n + 2, i+1); + else + return pow(x, n) / factorial(n) + evaluate(x, n + 2, i+1); +} + +int main() +{ + int n; + scanf("%d", &n); + printf("%f\n", evaluate(n, 1, 1)); +} \ No newline at end of file From 9ac3843cb9eca9b4d44e99ee76646fc4c73bc9a7 Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:28:03 +0600 Subject: [PATCH 08/19] 4 --- solutions/sadman/10/4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/sadman/10/4.c b/solutions/sadman/10/4.c index 0ace8c7..8fa48f1 100644 --- a/solutions/sadman/10/4.c +++ b/solutions/sadman/10/4.c @@ -1,4 +1,4 @@ -#include + #include #include #include From c71b8d16a457e6d3379b5ea0a7c9cd77a861fa5f Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:28:16 +0600 Subject: [PATCH 09/19] 10 | 5 | sharafat --- solutions/sharafat/10/4.c | 30 ++++++++++++++++++++++++++++++ solutions/sharafat/10/5.c | 22 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 solutions/sharafat/10/4.c create mode 100644 solutions/sharafat/10/5.c diff --git a/solutions/sharafat/10/4.c b/solutions/sharafat/10/4.c new file mode 100644 index 0000000..9f7e69e --- /dev/null +++ b/solutions/sharafat/10/4.c @@ -0,0 +1,30 @@ +// n order polinoial +// Generated with AI + +#include +#include + +int factorial(int n) +{ + if (n == 1) + return 1; + else + return n * factorial(n - 1); +} + +float evaluate(int x, int n, int i) +{ + if (n >= 11) + return 0; + else if (i % 2 == 0) + return -pow(x, n) / factorial(n) + evaluate(x, n + 2, i+1); + else + return pow(x, n) / factorial(n) + evaluate(x, n + 2, i+1); +} + +int main() +{ + int n; + scanf("%d", &n); + printf("%f\n", evaluate(n, 1, 1)); +} \ No newline at end of file diff --git a/solutions/sharafat/10/5.c b/solutions/sharafat/10/5.c new file mode 100644 index 0000000..f1b2ecc --- /dev/null +++ b/solutions/sharafat/10/5.c @@ -0,0 +1,22 @@ +#include + +void fibonacci(int n) +{ + int i, a = 0, b = 1, c; + for (i = 0; i < n; i++) + { + printf("%d ", a); + c = a + b; + a = b; + b = c; + } +} + +int main() +{ + int n; + printf("Enter number to generate fibonacci series: "); + scanf("%d", &n); + fibonacci(n); + printf("\n"); +} \ No newline at end of file From 532f13729a208f2413e012ee8f21e0fa67f9103a Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:28:31 +0600 Subject: [PATCH 10/19] 10 | 18 | sharafat --- solutions/sharafat/10/10.c | 44 +++++++++++++++++++++ solutions/sharafat/10/11.c | 32 +++++++++++++++ solutions/sharafat/10/12.c | 64 ++++++++++++++++++++++++++++++ solutions/sharafat/10/13.c | 67 +++++++++++++++++++++++++++++++ solutions/sharafat/10/14.c | 81 ++++++++++++++++++++++++++++++++++++++ solutions/sharafat/10/15.c | 50 +++++++++++++++++++++++ solutions/sharafat/10/16.c | 27 +++++++++++++ solutions/sharafat/10/17.c | 34 ++++++++++++++++ solutions/sharafat/10/18.c | 8 ++++ solutions/sharafat/10/6.c | 19 +++++++++ solutions/sharafat/10/7.c | 24 +++++++++++ solutions/sharafat/10/8.c | 23 +++++++++++ solutions/sharafat/10/9.c | 58 +++++++++++++++++++++++++++ 13 files changed, 531 insertions(+) create mode 100644 solutions/sharafat/10/10.c create mode 100644 solutions/sharafat/10/11.c create mode 100644 solutions/sharafat/10/12.c create mode 100644 solutions/sharafat/10/13.c create mode 100644 solutions/sharafat/10/14.c create mode 100644 solutions/sharafat/10/15.c create mode 100644 solutions/sharafat/10/16.c create mode 100644 solutions/sharafat/10/17.c create mode 100644 solutions/sharafat/10/18.c create mode 100644 solutions/sharafat/10/6.c create mode 100644 solutions/sharafat/10/7.c create mode 100644 solutions/sharafat/10/8.c create mode 100644 solutions/sharafat/10/9.c diff --git a/solutions/sharafat/10/10.c b/solutions/sharafat/10/10.c new file mode 100644 index 0000000..cebeb53 --- /dev/null +++ b/solutions/sharafat/10/10.c @@ -0,0 +1,44 @@ +#include +#include + +float perimeter(float a, float b, float c) +{ + return a + b + c; +} + +float area(float a, float b, float c) +{ + float s = (a + b + c) / 2; + return sqrt((s - a) * (s - b) * (s - c)); +} + +int main() +{ + float a, b, c; + char operation; + + printf("Enter first side: "); + scanf("%f", &a); + printf("Enter second side: "); + scanf("%f", &b); + printf("Enter third side: "); + scanf("%f", &c); + + printf("Enter one of the followings: "); + printf("\n(a) Perimeter of the triangle "); + printf("\n(b) Area of the triangle "); + printf("\n"); + + scanf(" %c", &operation); + switch (operation) + { + case 'a': + printf("Result -> %f\n", perimeter(a, b, c)); + break; + case 'b': + printf("Result -> %f\n", area(a, b, c)); + break; + default: + printf("Invalid operation\n"); + } +} diff --git a/solutions/sharafat/10/11.c b/solutions/sharafat/10/11.c new file mode 100644 index 0000000..3ccff8a --- /dev/null +++ b/solutions/sharafat/10/11.c @@ -0,0 +1,32 @@ +#include + +int find_largest(int *matrix, int rows, int cols) { + int i, j, largest = *matrix; + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + if (*(matrix + i * cols + j) > largest) { + largest = *(matrix + i * cols + j); + } + } + } + return largest; +} + +int main() { + int m, n, i, j; + printf("Enter number of rows and columns: "); + scanf("%d %d", &m, &n); + + int matrix[m][n]; + printf("Enter matrix elements: \n"); + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + scanf("%d", &matrix[i][j]); + } + } + + int largest = find_largest(&matrix[0][0], m, n); + printf("Largest element in the matrix is %d\n", largest); + + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/10/12.c b/solutions/sharafat/10/12.c new file mode 100644 index 0000000..88f665d --- /dev/null +++ b/solutions/sharafat/10/12.c @@ -0,0 +1,64 @@ +#include + +void multiply_matrices(int *matrix_one, int *matrix_two, int m, int n) +{ + int i, j, k; + int result[m][m]; + + for (i = 0; i < m; i++) + { + for (j = 0; j < m; j++) + { + + result[i][j] = 0; + for (k = 0; k < n; k++) + { + result[i][j] += *(matrix_one + i * n + k) * *(matrix_two + k * m + j); + } + } + } + + printf("Resultant matrix: \n"); + for (i = 0; i < m; i++) + { + printf("["); + for (j = 0; j < m; j++) + { + printf(" %d ", result[i][j]); + } + printf("]\n"); + } +} + +int main() +{ + int m, n; + printf("Enter m and n (mxn) (nxm): "); + scanf("%d %d", &m, &n); + + int matrix_one[m][n]; + int matrix_two[n][m]; + int i, j; + + printf("Enter matrix one elements: \n"); + for (i = 0; i < m; i++) + { + for (j = 0; j < n; j++) + { + printf("Enter element at (%d, %d): ", i, j); + scanf("%d", &matrix_one[i][j]); + } + } + + printf("Enter matrix two elements: \n"); + for (i = 0; i < n; i++) + { + for (j = 0; j < m; j++) + { + printf("Enter element at (%d, %d): ", i, j); + scanf("%d", &matrix_two[i][j]); + } + } + + multiply_matrices((int *)matrix_one, (int *)matrix_two, m, n); +} \ No newline at end of file diff --git a/solutions/sharafat/10/13.c b/solutions/sharafat/10/13.c new file mode 100644 index 0000000..4a00b4e --- /dev/null +++ b/solutions/sharafat/10/13.c @@ -0,0 +1,67 @@ +#include + +void input_matrix(int *matrix, int rows, int cols) +{ + int i, j; + printf("Enter matrix elements: \n"); + for (i = 0; i < rows; i++) + { + for (j = 0; j < cols; j++) + scanf("%d", &matrix[i * cols + j]); + } +} + +void print_matrix(int *matrix, int rows, int cols) +{ + int i, j; + printf("Matrix: \n"); + for (i = 0; i < rows; i++) + { + printf("["); + for (j = 0; j < cols; j++) + printf(" %d ", matrix[i * cols + j]); + printf("]\n"); + } +} + +void print_row_averages(int *matrix, int rows, int cols) +{ + int i, j; + printf("Row averages: \n"); + for (i = 0; i < rows; i++) + { + int sum = 0; + for (j = 0; j < cols; j++) + sum += matrix[i * cols + j]; + printf("%d\n", sum / cols); + } +} + +void print_col_averages(int *matrix, int rows, int cols) +{ + int i, j; + printf("Column averages: \n"); + for (i = 0; i < cols; i++) + { + int sum = 0; + for (j = 0; j < rows; j++) + sum += matrix[j * cols + i]; + printf("%d\n", sum / rows); + } +} + +int main() +{ + int m, n; + printf("Enter number of rows and columns: "); + scanf("%d %d", &m, &n); + + int matrix[m][n]; + input_matrix(&matrix[0][0], m, n); + + print_matrix(&matrix[0][0], m, n); + print_row_averages(&matrix[0][0], m, n); + print_col_averages(&matrix[0][0], m, n); + + return 0; +} diff --git a/solutions/sharafat/10/14.c b/solutions/sharafat/10/14.c new file mode 100644 index 0000000..4396b97 --- /dev/null +++ b/solutions/sharafat/10/14.c @@ -0,0 +1,81 @@ +// Develop a top-down modular program that will perform the following tasks: +// ``` +// (a) Read two integer arrays with unsorted elements. +// (b) Sort them in ascending order +// (c) Merge the sorted arrays +// (d) Print the sorted list +// ``` +// Use functions for carrying out each of the above tasks. The main function should have only function calls. + +#include + +void input_array(int *array, int size) +{ + int i; + printf("Enter array elements: \n"); + for (i = 0; i < size; i++) + scanf("%d", &array[i]); +} + +void print_array(int *array, int size) +{ + int i; + printf("Array: \n"); + for (i = 0; i < size; i++) + printf("%d ", array[i]); + printf("\n"); +} + +void sort_array(int *array, int size) +{ + int i, j; + for (i = 0; i < size; i++) + { + int min = array[i], min_index = i; + for (j = i + 1; j < size; j++) + { + if (array[j] < min) + { + min = array[j]; + min_index = j; + } + } + int temp = array[i]; + array[i] = array[min_index]; + array[min_index] = temp; + } +} + +void merge_arrays(int *array_one, int *array_two, int *result, int size_one, int size_two) +{ + int i, j; + for (i = 0; i < size_one; i++) + result[i] = array_one[i]; + for (j = 0; j < size_two; j++) + result[i + j] = array_two[j]; +} + +void operations(void) +{ + int m, n; + printf("Enter size of array one and array two: "); + scanf("%d %d", &m, &n); + int array_one[m], array_two[n]; + input_array(array_one, m); + input_array(array_two, n); + + sort_array(array_one, m); + sort_array(array_two, n); + + int result[m + n]; + merge_arrays(array_one, array_two, result, m, n); + sort_array(result, m+n); + + print_array(result, m + n); +} + +int main() +{ + operations(); + return 0; +} diff --git a/solutions/sharafat/10/15.c b/solutions/sharafat/10/15.c new file mode 100644 index 0000000..d6d411e --- /dev/null +++ b/solutions/sharafat/10/15.c @@ -0,0 +1,50 @@ +#include + +void copy_string(char *one, char *two) +{ + int i; + for (i=0; one[i] != '\0'; i++) + two[i] = one[i]; + two[i] = '\0'; + return; +} + +void compare_string(char *one, char *two) +{ + int i; + for (i=0; one[i] != '\0'; i++) + if (one[i] != two[i]) + break; + if (one[i] == '\0' && two[i] == '\0') + printf("Strings are equal\n"); + else + printf("Strings are not equal\n"); + return; +} + +void concat_string(char *one, char *two) +{ + int i, j; + for (i=0; one[i] != '\0'; i++); + for (j=0; two[j] != '\0'; j++) + one[i+j] = two[j]; + one[i+j] = '\0'; + return; +} + +int main() +{ + char string_one[100], string_two[200]; + printf("Enter your string: "); + fgets(string_one, 100, stdin); + + copy_string(string_one, string_two); + printf("Your second string is: %s", string_two); + + compare_string(string_one, string_two); + + concat_string(string_one, string_two); + printf("Your concatenated string is: %s", string_one); + + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/10/16.c b/solutions/sharafat/10/16.c new file mode 100644 index 0000000..aca6131 --- /dev/null +++ b/solutions/sharafat/10/16.c @@ -0,0 +1,27 @@ +#include + +int char_search_inside_string(char *string, char c) +{ + int i; + for (i=0; string[i] != '\0'; i++) + if (string[i] == c) + return i; + return -1; +} + +int main() +{ + char string[100], c; + printf("Enter your string: "); + fgets(string, 100, stdin); + printf("Enter your character: "); + scanf("%c", &c); + + int index = char_search_inside_string(string, c); + if (index == -1) + printf("Character not found\n"); + else + printf("Character found at index %d\n", index); + + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/10/17.c b/solutions/sharafat/10/17.c new file mode 100644 index 0000000..03e5a9b --- /dev/null +++ b/solutions/sharafat/10/17.c @@ -0,0 +1,34 @@ +#include + +char* locate(char *s1, char *s2, int m) +{ + int i, j; + static char temp[100]; + for (i=0; i< m; i++) + temp[i] = s1[i]; + for (j=0; s2[j] != '\0'; j++) + temp[i+j] = s2[j]; + for (; s1[i] != '\0'; i++) + temp[i+j] = s1[i]; + return temp; +} + +int main() +{ + char s1[100], s2[100]; + int m; + printf("Enter your string: "); + scanf("%[^\n]s", s1); + + printf("Enter your string: "); + scanf(" %[^\n]s", s2); + + printf("Enter your index: "); + scanf("%d", &m); + + char *updated_string; + updated_string = locate(s1, s2, m); + printf("Your string is: %s", updated_string); + + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/10/18.c b/solutions/sharafat/10/18.c new file mode 100644 index 0000000..9a00deb --- /dev/null +++ b/solutions/sharafat/10/18.c @@ -0,0 +1,8 @@ +#include + + + +int main() +{ + +} \ No newline at end of file diff --git a/solutions/sharafat/10/6.c b/solutions/sharafat/10/6.c new file mode 100644 index 0000000..193f444 --- /dev/null +++ b/solutions/sharafat/10/6.c @@ -0,0 +1,19 @@ +#include + +void rounded(float num, int round) +{ + printf("%.*f\n", round, num); +} + +int main() +{ + float num; + int round; + + printf("Enter number to round: "); + scanf("%f", &num); + printf("Enter number of decimal places to round to: "); + scanf("%d", &round); + + rounded(num, round); +} \ No newline at end of file diff --git a/solutions/sharafat/10/7.c b/solutions/sharafat/10/7.c new file mode 100644 index 0000000..119b276 --- /dev/null +++ b/solutions/sharafat/10/7.c @@ -0,0 +1,24 @@ +#include + +int check_prime(int number_to_check_prime) +{ + int i; + for (i = 2; i < number_to_check_prime; i++) + { + if (number_to_check_prime % i == 0) + return 0; + } + return 1; +} + +int main() +{ + int number_to_check_prime; + printf("Enter number to check prime: "); + scanf("%d", &number_to_check_prime); + + if (check_prime(number_to_check_prime)) + printf("%d is prime\n", number_to_check_prime); + else + printf("%d is not prime\n", number_to_check_prime); +} \ No newline at end of file diff --git a/solutions/sharafat/10/8.c b/solutions/sharafat/10/8.c new file mode 100644 index 0000000..e1ca206 --- /dev/null +++ b/solutions/sharafat/10/8.c @@ -0,0 +1,23 @@ +#include + +void to_uppercase(char *string) +{ + int i; + for (i = 0; string[i] != '\0'; i++) + { + if (string[i] >= 'a' && string[i] <= 'z') + string[i] -= 32; + } +} + +int main() +{ + char string[100]; + printf("Enter string: "); + scanf("%s", string); + + to_uppercase(string); + printf("Your uppercase string : \n"); + printf("%s\n", string); + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/10/9.c b/solutions/sharafat/10/9.c new file mode 100644 index 0000000..2bd264d --- /dev/null +++ b/solutions/sharafat/10/9.c @@ -0,0 +1,58 @@ +#include + +int sum(int a, int b) +{ + return a + b; +} + +int difference(int a, int b) +{ + return a - b; +} + +int product(int a, int b) +{ + return a * b; +} + +int division(int a, int b) +{ + return a / b; +} + +int main() +{ + int a, b; + char operation; + + printf("Enter first number: "); + scanf("%d", &a); + printf("Enter second number: "); + scanf("%d", &b); + + printf("Enter one of the followings: "); + printf("\n(a) Sum of the numbers "); + printf("\n(b) Difference of the numbers "); + printf("\n(c) Product of the numbers "); + printf("\n(d) Division of the numbers "); + printf("\n"); + + scanf(" %c", &operation); + switch (operation) + { + case 'a': + printf("Result -> %d\n", sum(a, b)); + break; + case 'b': + printf("Result -> %d\n", difference(a, b)); + break; + case 'c': + printf("Result -> %d\n", product(a, b)); + break; + case 'd': + printf("Result -> %d\n", division(a, b)); + break; + default: + printf("Invalid operation\n"); + } +} \ No newline at end of file From 003e5a80e54cb89e0f42e8b7aa0757f3b1dcd629 Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 4 Aug 2023 15:43:27 +0600 Subject: [PATCH 11/19] 10 | 19- 20 | sharafat --- solutions/sharafat/10/18.c | 14 ++++++++++++++ solutions/sharafat/10/19.c | 28 ++++++++++++++++++++++++++++ solutions/sharafat/10/20.c | 19 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 solutions/sharafat/10/19.c create mode 100644 solutions/sharafat/10/20.c diff --git a/solutions/sharafat/10/18.c b/solutions/sharafat/10/18.c index 9a00deb..91ed153 100644 --- a/solutions/sharafat/10/18.c +++ b/solutions/sharafat/10/18.c @@ -1,8 +1,22 @@ #include +char *month_name(int m) +{ + char *months[] = { + "January", "February", "March", "April", "May", "June", "July", "August", + "September", "October", "November", "December"}; + return months[m - 1]; +} int main() { + int m; + + printf("Enter month number: "); + scanf("%d", &m); + + printf("Month name: %s\n", month_name(m)); + return 0; } \ No newline at end of file diff --git a/solutions/sharafat/10/19.c b/solutions/sharafat/10/19.c new file mode 100644 index 0000000..747ccb7 --- /dev/null +++ b/solutions/sharafat/10/19.c @@ -0,0 +1,28 @@ +#include + +int leap(int year) +{ + if (year % 400 == 0) + return 1; + else if (year % 100 == 0) + return 0; + else if (year % 4 == 0) + return 1; + else + return 0; +} + +int main() +{ + int year; + + printf("Enter year: "); + scanf("%d", &year); + + if (leap(year)) + printf("%d is a leap year.\n", year); + else + printf("%d is not a leap year.\n", year); + + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/10/20.c b/solutions/sharafat/10/20.c new file mode 100644 index 0000000..dd8aa24 --- /dev/null +++ b/solutions/sharafat/10/20.c @@ -0,0 +1,19 @@ +#include +#include + +double round2(double x) +{ + return round(x * 100) / 100; +} + +int main() +{ + double x; + + printf("Enter a floating point value: "); + scanf("%lf", &x); + + printf("Rounded value: %.2lf\n", round2(x)); + + return 0; +} From 8a179aa99db6baf1d39897de9c496cd74bac0151 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 4 Aug 2023 09:43:53 +0000 Subject: [PATCH 12/19] updated logs --- README.md | 244 +++++++++++++++++++++++++++++------------------------- 1 file changed, 132 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index a147e57..8eb3d32 100644 --- a/README.md +++ b/README.md @@ -203,12 +203,12 @@ Indian currency notes. 1. Write a program that reads a floating-point number and then displays the right-most digit of the integral part of the number. -- [sharafat](solutions/sharafat/4/1.c) - [sadman](solutions/sadman/4/1.c) +- [sharafat](solutions/sharafat/4/1.c) 2. Modify the above program to display the two right most digits of the integral part of the number. -- [sharafat](solutions/sharafat/4/2.c) - [sadman](solutions/sadman/4/2.c) +- [sharafat](solutions/sharafat/4/2.c) 3. Given an integer number, write a program that displays the number as follows: ``` @@ -223,8 +223,8 @@ For example, the number 5678 will be displayed as 7 8 8 ``` -- [sharafat](solutions/sharafat/4/3.c) - [sadman](solutions/sadman/4/3.c) +- [sharafat](solutions/sharafat/4/3.c) 4. The straight-line method of computing the yearly depreciation of the value of an item is given by ``` @@ -232,8 +232,8 @@ For example, the number 5678 will be displayed as ``` Write a program to determine the salvage value of an item when the purchase price, years of service, and the annual depreciation are given. -- [sharafat](solutions/sharafat/4/4.c) - [sadman](solutions/sadman/4/4.c) +- [sharafat](solutions/sharafat/4/4.c) 5. Write a program that will read a real number from the keyboard and print the following output in one line: @@ -242,8 +242,8 @@ Smallest integer The given Lergest integer not less than number not greater than the number the number ``` -- [sharafat](solutions/sharafat/4/5.c) - [sadman](solutions/sadman/4/5.c) +- [sharafat](solutions/sharafat/4/5.c) 6. The total distance travelled by a vehicle in t seconds is given by ``` @@ -253,8 +253,8 @@ distance = ut + ( a t*2 ) / 2 program to evaluate the distance travelled at regular intervals of time, given the values of u and a. > The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of u and a . -- [sharafat](solutions/sharafat/4/6.c) - [sadman](solutions/sadman/4/6.c) +- [sharafat](solutions/sharafat/4/6.c) 7. In inventory management, the Economic Order Quantity for a single item is given by ``` @@ -266,8 +266,8 @@ TBO = sqrt ((2* setup costs) / (demand rate * holding cost per unit time)) ``` Write a program to compute EOQ and TBO, given demand rate (items per unit time), setup costs (per order), and the holding cost (per item per unit time). -- [sharafat](solutions/sharafat/4/7.c) - [sadman](solutions/sadman/4/7.c) +- [sharafat](solutions/sharafat/4/7.c) 8. For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency is given by @@ -276,22 +276,22 @@ Frequency = sqrt ((1 / L*C )- (R*R / 4*C*C) ``` It is desired to study the variation of this frequency with C (capacitance). Write a program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01. -- [sharafat](solutions/sharafat/4/8.c) - [sadman](solutions/sadman/4/8.c) +- [sharafat](solutions/sharafat/4/8.c) 9. Write a program to read a four digit integer and print the sum of its digits. Hint: Use / and % operators. -- [sharafat](solutions/sharafat/4/9.c) - [sadman](solutions/sadman/4/9.c) +- [sharafat](solutions/sharafat/4/9.c) 10. Given three values, write a program to read three values from keyboard and print out the largest of them without using if statement. -- [sharafat](solutions/sharafat/4/10.c) - [sadman](solutions/sadman/4/10.c) +- [sharafat](solutions/sharafat/4/10.c) 11. Write a program to read two integer values m and n and to decide and print whether m is a multiple of n. -- [sharafat](solutions/sharafat/4/11.c) - [sadman](solutions/sadman/4/11.c) +- [sharafat](solutions/sharafat/4/11.c) 12. Write a program to read three values using scanf statement and print the following results: ``` @@ -300,13 +300,13 @@ them without using if statement. (c) Largest of the three (d) Smallest of the three ``` -- [sharafat](solutions/sharafat/4/12.c) - [sadman](solutions/sadman/4/12.c) +- [sharafat](solutions/sharafat/4/12.c) 13. The cost of one type of mobile service is Rs. 250 plus Rs. 1.25 for each call made over and above 100 calls. Write a program to read customer codes and calls made and print the bill for each customer. -- [sharafat](solutions/sharafat/4/13.c) - [sadman](solutions/sadman/4/13.c) +- [sharafat](solutions/sharafat/4/13.c) 14. Write a program to print a table of sin and cos functions for the interval from 0 to 180 degrees in increments of 15 a shown here. @@ -317,8 +317,8 @@ degrees in increments of 15 a shown here. | ... | ... | ... | | ... | ... | ... | | 180 | ... | ... | -- [sharafat](solutions/sharafat/4/14.c) - [sadman](solutions/sadman/4/14.c) +- [sharafat](solutions/sharafat/4/14.c) 15. Write a program to compute the values of square roots and squares of the numbers 0 to 100 in steps 10 and print the output in a tabular form as shown below. @@ -327,35 +327,35 @@ degrees in increments of 15 a shown here. | ------ | ----------- | ------ | | 0 | 0 | 0 | | 100 | 10 | 10000 | -- [sharafat](solutions/sharafat/4/15.c) - [sadman](solutions/sadman/4/15.c) +- [sharafat](solutions/sharafat/4/15.c) 16. Write a program to illustrate the use of cast operator in a real life situation. -- [sharafat](solutions/sharafat/4/16.c) - [sadman](solutions/sadman/4/16.c) +- [sharafat](solutions/sharafat/4/16.c) 17. Write a C program to shift the given data by two bits to the left. -- [sharafat](solutions/sharafat/4/17.c) - [sadman](solutions/sadman/4/17.c) +- [sharafat](solutions/sharafat/4/17.c) 18. Write a C program to compute the value of the expression `x=a-b/3+c*2-1`. -- [sharafat](solutions/sharafat/4/18.c) - [sadman](solutions/sadman/4/18.c) +- [sharafat](solutions/sharafat/4/18.c) 19. Write a C program to input a date value and determine whether the entered day, month, and year values are valid. -- [sharafat](solutions/sharafat/4/19.c) - [sadman](solutions/sadman/4/19.c) +- [sharafat](solutions/sharafat/4/19.c) 20. Write a C program to input the sides of a triangle and determine whether the triangle is isoceles or not. -- [sharafat](solutions/sharafat/4/20.c) - [sadman](solutions/sadman/4/20.c) +- [sharafat](solutions/sharafat/4/20.c) 21. Write a C program that reads two numbers and performs their division. If the division is not possible, then an error messgage, ‘Division not possible’ is displayed. -- [sharafat](solutions/sharafat/4/21.c) - [sadman](solutions/sadman/4/21.c) +- [sharafat](solutions/sharafat/4/21.c) 22. Input the value of 4 variables a, b, c and d and compute the resultant value of following expressions: @@ -364,8 +364,8 @@ expressions: (a + b) * c / d a + (b * c) / d ``` -- [sharafat](solutions/sharafat/4/22.c) - [sadman](solutions/sadman/4/22.c) +- [sharafat](solutions/sharafat/4/22.c) ## Chapter 5 @@ -377,9 +377,9 @@ display the same in the following formats: PROCESSING (c) W.P. ``` +- [sadman](solutions/sadman/5/1.c) - [NAYEMA](solutions/NAYEMA/5/1.c) - [sharafat](solutions/sharafat/5/1.c) -- [sadman](solutions/sadman/5/1.c) 2. Write a program to read the values of x and y and print the results of the following expressions in one @@ -389,15 +389,15 @@ line: (b) (x+y) /2 (c) (x+y)(x–y) ``` +- [sadman](solutions/sadman/5/2.c) - [NAYEMA](solutions/NAYEMA/5/2.c) - [sharafat](solutions/sharafat/5/2.c) -- [sadman](solutions/sadman/5/2.c) 3. Write a program to read the following numbers, round them off to the nearest integers and print out the results in integer form: 35.7 50.21 – 23.73 – 46.45 +- [sadman](solutions/sadman/5/3.c) - [NAYEMA](solutions/NAYEMA/5/3.c) - [sharafat](solutions/sharafat/5/3.c) -- [sadman](solutions/sadman/5/3.c) 4. Write a program that reads 4 floating point values in the range, 0.0 to 20.0, and prints a horizontal bar chart to represent these values using the character * as the fill character. For the purpose of the chart, @@ -409,9 +409,9 @@ represented as follows. * * * * ``` > Note that the actual values are shown at the end of each bar. +- [sadman](solutions/sadman/5/4.c) - [NAYEMA](solutions/NAYEMA/5/4.c) - [sharafat](solutions/sharafat/5/4.c) -- [sadman](solutions/sadman/5/4.c) 5. Write an interactive program to demonstrate the process of multiplication. The program should ask the user to enter two two-digit integers and print the product of integers as shown below. @@ -425,9 +425,9 @@ the user to enter two two-digit integers and print the product of integers as sh Add them 1665 _______________ ``` +- [sadman](solutions/sadman/5/5.c) - [NAYEMA](solutions/NAYEMA/5/5.c) - [sharafat](solutions/sharafat/5/5.c) -- [sadman](solutions/sadman/5/5.c) 6. Write a program to read three integers from the keyboard using one scanf statement and output them on one line using: @@ -436,9 +436,9 @@ them on one line using: (b) only one printf with conversion specifiers, and (c) only one printf without conversion specifiers. ``` +- [sadman](solutions/sadman/5/6.c) - [NAYEMA](solutions/NAYEMA/5/6.c) - [sharafat](solutions/sharafat/5/6.c) -- [sadman](solutions/sadman/5/6.c) 7. Write a program that prints the value 10.45678 in exponential format with the following specifications: ``` @@ -446,9 +446,9 @@ them on one line using: (b) correct to four decimal places; and (c) correct to eight decimal places. ``` +- [sadman](solutions/sadman/5/7.c) - [NAYEMA](solutions/NAYEMA/5/7.c) - [sharafat](solutions/sharafat/5/7.c) -- [sadman](solutions/sadman/5/7.c) 8. Write a program to print the value 345.6789 in fixed-point format with the following specifications: ``` @@ -456,9 +456,9 @@ them on one line using: (b) correct to five decimal places; and (c) correct to zero decimal places. ``` +- [sadman](solutions/sadman/5/8.c) - [NAYEMA](solutions/NAYEMA/5/8.c) - [sharafat](solutions/sharafat/5/8.c) -- [sadman](solutions/sadman/5/8.c) 9. Write a program to read the name ANIL KUMAR GUPTA in three parts using the scanf statement and to display the same in the following format using the printf statement. @@ -467,9 +467,9 @@ to display the same in the following format using the printf statement. (b) A.K. GUPTA (c) GUPTA A.K. ``` +- [sadman](solutions/sadman/5/9.c) - [NAYEMA](solutions/NAYEMA/5/9.c) - [sharafat](solutions/sharafat/5/9.c) -- [sadman](solutions/sadman/5/9.c) 10. Write a program to read and display the following table of data. ``` @@ -478,26 +478,26 @@ to display the same in the following format using the printf statement. Motor 450 5786.70 ``` > The name and code must be left-justified and price must be right justified. +- [sadman](solutions/sadman/5/10.c) - [NAYEMA](solutions/NAYEMA/5/10.c) - [sharafat](solutions/sharafat/5/10.c) -- [sadman](solutions/sadman/5/10.c) 11. Write a C program to print inventory stock report using some sample data. The report should show item code, quantity and inventory location as formatted output. +- [sadman](solutions/sadman/5/11.c) - [NAYEMA](solutions/NAYEMA/5/11.c) - [sharafat](solutions/sharafat/5/11.c) -- [sadman](solutions/sadman/5/11.c) 12. Write a C program to display the Pascal’s triangle. +- [sadman](solutions/sadman/5/12.c) - [NAYEMA](solutions/NAYEMA/5/12.c) - [sharafat](solutions/sharafat/5/12.c) -- [sadman](solutions/sadman/5/12.c) 13. Write a C program to input a currency value in Dollars and display its equivalent Euro and INR amounts. You may use current exchange rate for conversion purpose. +- [sadman](solutions/sadman/5/13.c) - [NAYEMA](solutions/NAYEMA/5/13.c) - [sharafat](solutions/sharafat/5/13.c) -- [sadman](solutions/sadman/5/13.c) 14. Write a C program to display the following pattern. ``` @@ -507,14 +507,14 @@ INR amounts. You may use current exchange rate for conversion purpose. 2 1 1 ``` -- [NAYEMA](solutions/NAYEMA/5/14.c) - [sadman](solutions/sadman/5/14.c) +- [NAYEMA](solutions/NAYEMA/5/14.c) 15. Write a C program to input an investment amount and compute its fixed deposit cumulative return after 10 years at arate of interest of 8.75%. +- [sadman](solutions/sadman/5/15.c) - [NAYEMA](solutions/NAYEMA/5/15.c) - [sharafat](solutions/sharafat/5/15.c) -- [sadman](solutions/sadman/5/15.c) ## Chapter 6 @@ -526,14 +526,14 @@ NUMBER IS ODD (a) without using else option and (b) with else option. ``` -- [sharafat](solutions/sharafat/6/1.c) - [sadman](solutions/sadman/6/1.c) +- [sharafat](solutions/sharafat/6/1.c) 2. Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7. +- [sadman](solutions/sadman/6/2.c) - [NAYEMA](solutions/NAYEMA/6/2.c) - [sharafat](solutions/sharafat/6/2.c) -- [sadman](solutions/sadman/6/2.c) 3. A set of two linear equations with two unknowns x1 and x2 is given below: ``` @@ -563,9 +563,9 @@ students: (h) in the range 0 to 40. ``` The program should use a minimum number of if statements. +- [sadman](solutions/sadman/6/4.c) - [NAYEMA](solutions/NAYEMA/6/4.c) - [sharafat](solutions/sharafat/6/4.c) -- [sadman](solutions/sadman/6/4.c) 5. Admission to a professional course is subject to the following conditions: ``` @@ -577,9 +577,9 @@ The program should use a minimum number of if statements. or, Total in Mathematics and Physics >= 150 Given the marks in the three subjects, write a program to process the applications to list the eligible candidates. +- [sadman](solutions/sadman/6/5.c) - [NAYEMA](solutions/NAYEMA/6/5.c) - [sharafat](solutions/sharafat/6/5.c) -- [sadman](solutions/sadman/6/5.c) 6. Write a program to print a two-dimensional Square Root Table as shown below, to provide the square root of any number from 0 to 9.9. For example, the value x will give the square root of 3.2 and y the @@ -594,9 +594,9 @@ square root of 3.9. | 0.3 | | | x | | y | | ... | | | | | | | 0.9 | | | | | | +- [sadman](solutions/sadman/6/6.c) - [NAYEMA](solutions/NAYEMA/6/6.c) - [sharafat](solutions/sharafat/6/6.c) -- [sadman](solutions/sadman/6/6.c) 7. Shown below is a Floyd’s triangle. ``` @@ -616,9 +616,9 @@ square root of 3.9. 0 1 0 1 1 0 1 0 1 ``` +- [sadman](solutions/sadman/6/7.c) - [NAYEMA](solutions/NAYEMA/6/7.c) - [sharafat](solutions/sharafat/6/7.c) -- [sadman](solutions/sadman/6/7.c) 8. A cloth showroom has announced the following seasonal discounts on purchase of items: > @@ -629,14 +629,14 @@ square root of 3.9. | 101 - 200 | 5% | 7.5% | | 201 - 300 | 7.5% | 10% | | Above 300 | 10% | 15% | +- [sadman](solutions/sadman/6/8.c) - [NAYEMA](solutions/NAYEMA/6/8.c) - [sharafat](solutions/sharafat/6/8.c) -- [sadman](solutions/sadman/6/8.c) Write a program using switch and if statements to compute the net amount to be paid by a customer +- [sadman](solutions/sadman/6/9.c) - [NAYEMA](solutions/NAYEMA/6/9.c) - [sharafat](solutions/sharafat/6/9.c) -- [sadman](solutions/sadman/6/9.c) 9. Write a program that will read the value of x and evaluate the following function, ``` @@ -650,8 +650,8 @@ using, (b) else if statements, and (c) conditional operator ? : ``` -- [sharafat](solutions/sharafat/6/10.c) - [sadman](solutions/sadman/6/10.c) +- [sharafat](solutions/sharafat/6/10.c) 10. Write a program to compute the real roots of a quadratic equation ``` @@ -673,13 +673,13 @@ constants a, b and c and print the values of x 1 and x 2. ``` Test your program with appropriate data so that all logical paths are working as per your design. Incorporate appropriate output messages. -- [sharafat](solutions/sharafat/6/11.c) - [sadman](solutions/sadman/6/11.c) +- [sharafat](solutions/sharafat/6/11.c) 11. Write a program to read three integer values from the keyboard and displays the output stating that they are the sides of right-angled triangle. -- [sharafat](solutions/sharafat/6/12.c) - [sadman](solutions/sadman/6/12.c) +- [sharafat](solutions/sharafat/6/12.c) 12. An electricity board charges the following rates for the use of electricity: ``` @@ -691,21 +691,21 @@ All users are charged a minimum of Rs. 100 as meter charge. If the total amount then an additional surcharge of 15% of total amount is charged. Write a program to read the names of users and number of units consumed and print out the charges with names. -- [sharafat](solutions/sharafat/6/13.c) - [sadman](solutions/sadman/6/13.c) +- [sharafat](solutions/sharafat/6/13.c) 13. Write a program to compute and display the sum of all integers that are divisible by 6 but not divisible by 4 and lie between 0 and 100. The program should also count and display the number of such values. -- [sharafat](solutions/sharafat/6/14.c) - [sadman](solutions/sadman/6/14.c) +- [sharafat](solutions/sharafat/6/14.c) 14. Write an interactive program that could read a positive integer number and decide whether the number is a prime number and display the output accordingly. Modify the program to count all the prime numbers that lie between 100 and 200. > NOTE : A prime number is a positive integer that is divisible only by 1 or by itself. -- [sharafat](solutions/sharafat/6/15.c) - [sadman](solutions/sadman/6/15.c) +- [sharafat](solutions/sharafat/6/15.c) 15. Write a program to read a double-type value x that represents angle in radians and a character-type variable T that represents the type of trigonometric function and display the value of @@ -715,13 +715,13 @@ variable T that represents the type of trigonometric function and display the va (c) tan (x), if t or T is assigned to T ``` using, (i) if......else statement , and (ii) switch statement. -- [sharafat](solutions/sharafat/6/16.c) - [sadman](solutions/sadman/6/16.c) +- [sharafat](solutions/sharafat/6/16.c) 16. Write a C program to input the numeric week day value (starting from Monday as 1) and display the corresponding name of the week day. -- [sharafat](solutions/sharafat/6/17.c) - [sadman](solutions/sadman/6/17.c) +- [sharafat](solutions/sharafat/6/17.c) 17. Write a C program to input two numbers a and b and display whether ``` @@ -729,8 +729,8 @@ corresponding name of the week day. (b) b is greater than b (c) or, a and b are equal ``` -- [sharafat](solutions/sharafat/6/18.c) - [sadman](solutions/sadman/6/18.c) +- [sharafat](solutions/sharafat/6/18.c) 18. Write a C program to input the total percentage of marks of a student and display its Division using below rules: @@ -739,14 +739,14 @@ below rules: (b) Greater than or equal to 60 percent and less than 80 per cent - “Second Division” (c) Less than 60 percent - “Third Division" ``` -- [sharafat](solutions/sharafat/6/19.c) - [sadman](solutions/sadman/6/19.c) +- [sharafat](solutions/sharafat/6/19.c) 19. Using Switch case block, input the name of the month from the user and display the corresponding number of days in that month. +- [sadman](solutions/sadman/6/20.c) - [NAYEMA](solutions/NAYEMA/6/20.c) - [sharafat](solutions/sharafat/6/20.c) -- [sadman](solutions/sadman/6/20.c) 20. Write a C program that inputs a string and counts the number of capital and small alphabets in that string. @@ -763,12 +763,12 @@ should be written as ``` > ( Hint: Use modulus operator to extract the last digit and the integer division by 10 to get the n–1 digit number from the n digit number.) -- [sharafat](solutions/sharafat/7/1.c) - [sadman](solutions/sadman/7/1.c) +- [sharafat](solutions/sharafat/7/1.c) 2. Write a program to compute the sum of the digits of a given integer number. -- [sharafat](solutions/sharafat/7/2.c) - [sadman](solutions/sadman/7/2.c) +- [sharafat](solutions/sharafat/7/2.c) 3. The numbers in the sequence ``` @@ -777,8 +777,8 @@ digit number from the n digit number.) are called Fibonacci numbers. Write a program using a do....while loop to calculate and print the first m Fibonacci numbers. > ( Hint: After the first two numbers in the series, each number is the sum of the two preceding numbers.) -- [sharafat](solutions/sharafat/7/3.c) - [sadman](solutions/sadman/7/3.c) +- [sharafat](solutions/sharafat/7/3.c) 4. Write a program to evaluate the following investment equation ``` @@ -799,8 +799,8 @@ be recursively written as ``` That is, the value of money at the end of first year becomes the principal amount for the next year and so on.) -- [sharafat](solutions/sharafat/7/4.c) - [sadman](solutions/sadman/7/4.c) +- [sharafat](solutions/sharafat/7/4.c) 5. Write programs to print the following outputs using for loops. ``` @@ -811,18 +811,18 @@ so on.) 4 4 4 4 * * 5 5 5 5 5 * ``` -- [sharafat](solutions/sharafat/7/5.c) - [sadman](solutions/sadman/7/5.c) +- [sharafat](solutions/sharafat/7/5.c) 6. Write a program to read the age of 100 persons and count the number of persons in the age group 50 to 60. Use for and continue statements. -- [sharafat](solutions/sharafat/7/6.c) - [sadman](solutions/sadman/7/6.c) +- [sharafat](solutions/sharafat/7/6.c) 7. Rewrite the program of case study 7.4 (plotting of two curves) using else...if constructs instead of continue statements. -- [sharafat](solutions/sharafat/7/7.c) - [sadman](solutions/sadman/7/7.c) +- [sharafat](solutions/sharafat/7/7.c) 8. Write a program to print a table of values of the function ``` @@ -841,8 +841,8 @@ for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as foll | . | | | | | | | . | | | | | | |9.0| | | | | | -- [sharafat](solutions/sharafat/7/8.c) - [sadman](solutions/sadman/7/8.c) +- [sharafat](solutions/sharafat/7/8.c) 9. Write a program using for and if statement to display the capital letter S in a grid of 15 rows and 18 columns as shown below. @@ -864,8 +864,8 @@ for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as foll ***-----------**** **------------**** ``` -- [sharafat](solutions/sharafat/7/9.c) - [sadman](solutions/sadman/7/9.c) +- [sharafat](solutions/sharafat/7/9.c) 10. Write a program to compute the value of Euler’s number e, that is used as the base of natural logarithms. Use the following formula. @@ -874,8 +874,8 @@ logarithms. Use the following formula. ``` Use a suitable loop construct. The loop must terminate when the difference between two successive values of e is less than 0.00001. -- [sharafat](solutions/sharafat/7/10.c) - [sadman](solutions/sadman/7/10.c) +- [sharafat](solutions/sharafat/7/10.c) 11. Write programs to evaluate the following functions to 0.0001% accuracy. ``` @@ -883,8 +883,8 @@ successive values of e is less than 0.00001. (b) cosx = 1 – x 2 /2! + x 4 /4! – x 6 /6! + . . . . . (c) SUM = 1 + (1/2) 2 + (1/3) 3 + (1/4) 4 + … … ``` -- [sharafat](solutions/sharafat/7/11.c) - [sadman](solutions/sadman/7/11.c) +- [sharafat](solutions/sharafat/7/11.c) 12. The present value (popularly known as book value) of an item is given by the relationship. ``` @@ -898,8 +898,8 @@ successive values of e is less than 0.00001. If P is considered the scrap value at the end of useful life of the item, write a program to compute the useful life in years given the original cost, depreciation rate, and the scrap value. The program should request the user to input the data interactively. -- [sharafat](solutions/sharafat/7/12.c) - [sadman](solutions/sadman/7/12.c) +- [sharafat](solutions/sharafat/7/12.c) 13. Write a program to print a square of size 5 by using the character N as shown below: ``` @@ -911,16 +911,16 @@ The program should request the user to input the data interactively. n n n n n n n n n n ``` > n is used insted of S in the above figure LOL. -- [sharafat](solutions/sharafat/7/13.c) - [sadman](solutions/sadman/7/13.c) +- [sharafat](solutions/sharafat/7/13.c) 14. Write a program to graph the function ``` y = sin (x) ``` in the interval 0 to 180 degrees in steps of 15 degrees. Use the concepts discussed in the Case Study 4 in Chapter 7. -- [sharafat](solutions/sharafat/7/14.c) - [sadman](solutions/sadman/7/14.c) +- [sharafat](solutions/sharafat/7/14.c) 15. Modify the program of Exercise 7.16 to print the character S instead of N at the center of the square as shown below. ``` @@ -931,17 +931,17 @@ in the interval 0 to 180 degrees in steps of 15 degrees. Use the concepts discus n n n n n ``` > n is used insted of S in the above figure LOL. -- [sharafat](solutions/sharafat/7/15.c) - [sadman](solutions/sadman/7/15.c) +- [sharafat](solutions/sharafat/7/15.c) 16. Given a set of 10 two-digit integers containing both positive and negative values, write a program using for loop to compute the sum of all positive values and print the sum and the number of values added. The program should use scanf to read the values and terminate when the sum exceeds 999. Do not use goto statement. -- [sharafat](solutions/sharafat/7/16.c) - [sadman](solutions/sadman/7/16.c) +- [sharafat](solutions/sharafat/7/16.c) 17. Write a C program to display a coloured line. -- [sharafat](solutions/sharafat/7/17.c) - [sadman](solutions/sadman/7/17.c) +- [sharafat](solutions/sharafat/7/17.c) 18. Write a C program to display the following pattern. ``` @@ -951,8 +951,8 @@ The program should use scanf to read the values and terminate when the sum excee C D E F 5 6 7 8 9 ``` -- [sharafat](solutions/sharafat/7/18.c) - [sadman](solutions/sadman/7/18.c) +- [sharafat](solutions/sharafat/7/18.c) 19. Write a C program to display the following pattern: ``` @@ -962,8 +962,8 @@ The program should use scanf to read the values and terminate when the sum excee 1 2 1 1 ``` -- [sharafat](solutions/sharafat/7/19.c) - [sadman](solutions/sadman/7/19.c) +- [sharafat](solutions/sharafat/7/19.c) 20. Write a C program to display the following pattern: ``` @@ -986,8 +986,8 @@ y = mx + c ``` and the values of m and c are given y the following equations: > All summations are from 1 to n. -- [sharafat](solutions/sharafat/8/1.c) - [sadman](solutions/sadman/8/1.c) +- [sharafat](solutions/sharafat/8/1.c) 2. The daily maximum temperatures recorded in 10 cities during the month of January (for all 31 days) have been tabulated. Write a program to read the table elements into a two-dimensional array temperature , and to find the city and day corresponding to @@ -995,12 +995,12 @@ Write a program to read the table elements into a two-dimensional array temperat (a) the highest temperature and (b) the lowest temperature. ``` -- [sharafat](solutions/sharafat/8/2.c) - [sadman](solutions/sadman/8/2.c) +- [sharafat](solutions/sharafat/8/2.c) 3. An election is contested by 5 candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count . In case, a number read is outside the range 1 to 5, the ballot should be considered as a ‘spoilt ballot’ and the program should also count the number of spoilt ballots. -- [sharafat](solutions/sharafat/8/3.c) - [sadman](solutions/sadman/8/3.c) +- [sharafat](solutions/sharafat/8/3.c) 4. The following set of numbers is popularly known as Pascal’s triangle. ``` @@ -1017,8 +1017,8 @@ If we denote rows by i and columns by j, then any element p ij = p i–1 ,j–1 + p i–1 ,j ``` Write a program to calculate the elements of the Pascal triangle for 10 rows and print the results. -- [sharafat](solutions/sharafat/8/4.c) - [sadman](solutions/sadman/8/4.c) +- [sharafat](solutions/sharafat/8/4.c) 5. The annual examination results of 100 students are tabulated as follows: > @@ -1034,12 +1034,12 @@ Write a program to read the data and determine the following: (b) The highest marks in each subject and the Roll No. of the student who secured it. (c) The student who obtained the highest total marks. ``` -- [sharafat](solutions/sharafat/8/5.c) - [sadman](solutions/sadman/8/5.c) +- [sharafat](solutions/sharafat/8/5.c) 6. Given are two one-dimensional arrays A and B which are sorted in ascending order. Write a program to merge them into a single sorted array that contains every item from arrays A and B, in ascending order. -- [sharafat](solutions/sharafat/8/6.c) - [sadman](solutions/sadman/8/6.c) +- [sharafat](solutions/sharafat/8/6.c) 7. Two matrices that have the same number of rows and columns can be multiplied to produce a third matrix. Consider the following two matrices. The product of A and B is a third matrix C of size n¥ n where each element of C is given by the following equation. @@ -1047,8 +1047,8 @@ The product of A and B is a third matrix C of size n¥ n where each element of C multiplied_matrix[i][j] += first_matrix[i][k] * second_matrix[k][j]; ``` Write a program that will read the values of elements of A and B and produce the product matrix C. -- [sharafat](solutions/sharafat/8/7.c) - [sadman](solutions/sadman/8/7.c) +- [sharafat](solutions/sharafat/8/7.c) 8. Write a program that fills a five-by-five matrix as follows: ``` @@ -1057,12 +1057,12 @@ Write a program that will read the values of elements of A and B and produce the - Right to left diagonal with zeros Display the contents of the matrix using not more than two printf statements. ``` -- [sharafat](solutions/sharafat/8/8.c) - [sadman](solutions/sadman/8/8.c) +- [sharafat](solutions/sharafat/8/8.c) 9. Selection sort is based on the following idea: Selecting the largest array element and swapping it with the last array element leaves an unsorted list whose size is 1 less than the size of the original list. If we repeat this step again on the unsorted list we will have an ordered list of size 2 and an unordered list size n–2 . When we repeat this until the size of the unsorted list becomes one, the result will be a sorted list. Write a program to implement this algorithm. -- [sharafat](solutions/sharafat/8/9.c) - [sadman](solutions/sadman/8/9.c) +- [sharafat](solutions/sharafat/8/9.c) 10. Develop a program to implement the binary search algorithm. This technique compares the search key value with the value of the element that is midway in a “sorted” list. Then; ``` @@ -1072,20 +1072,20 @@ Display the contents of the matrix using not more than two printf statements. ``` Repeat this “divide-and-conquer” strategy until we have a match. If the list is reduced to one nonmatching element, then the list does not contain the key value. Use the sorted list created in Exercise 8.9 or use any other sorted list. -- [sharafat](solutions/sharafat/8/10.c) - [sadman](solutions/sadman/8/10.c) +- [sharafat](solutions/sharafat/8/10.c) 11. Write a program that will compute the length of a given character string. -- [sharafat](solutions/sharafat/8/11.c) - [sadman](solutions/sadman/8/11.c) +- [sharafat](solutions/sharafat/8/11.c) 12. Write a program that will count the number occurrences of a specified character in a given line of text. Test your program. -- [sharafat](solutions/sharafat/8/12.c) - [sadman](solutions/sadman/8/12.c) +- [sharafat](solutions/sharafat/8/12.c) 13. Write a program to read a matrix of size m ¥ n and print its transpose. -- [sharafat](solutions/sharafat/8/13.c) - [sadman](solutions/sadman/8/13.c) +- [sharafat](solutions/sharafat/8/13.c) 14. Every book published by international publishers should carry an International Standard Book Number (ISBN). It is a 10 character 4 part number as shown below. ``` @@ -1096,42 +1096,42 @@ The first part denotes the region, the second represents publisher, the third id Sum = (1 × first digit) + (2 × second digit) + (3 ×third digit) + - - - - + (9 × ninth digit). ``` Check digit is the remainder when sum is divided by 11. Write a program that reads a given ISBN number and checks whether it represents a valid ISBN. -- [sharafat](solutions/sharafat/8/14.c) - [sadman](solutions/sadman/8/14.c) +- [sharafat](solutions/sharafat/8/14.c) 15. Write a program to read two matrices A and B and print the following: ``` (a) A + B; and (b) A – B. ``` -- [sharafat](solutions/sharafat/8/15.c) - [sadman](solutions/sadman/8/15.c) +- [sharafat](solutions/sharafat/8/15.c) 16. Write a C program to compute the sum of elements of two one-dimensional arrays and store the corresponding result in another array. -- [sharafat](solutions/sharafat/8/16.c) - [sadman](solutions/sadman/8/16.c) +- [sharafat](solutions/sharafat/8/16.c) 17. Write a C program to identify and count all the odd numbers in an array and calculate their sum. -- [sharafat](solutions/sharafat/8/17.c) - [sadman](solutions/sadman/8/17.c) +- [sharafat](solutions/sharafat/8/17.c) 18. Write a C program to input an amount in Indian currency and deduce the minimum currency denomination for that amount. -- [sharafat](solutions/sharafat/8/18.c) - [sadman](solutions/sadman/8/18.c) +- [sharafat](solutions/sharafat/8/18.c) 19. Write a C program to input a Roman number and compute its decimal equivalent. - [sharafat](solutions/sharafat/8/19.c) 20. Write a C program to input two NXN matrices and deduce their sum and product. -- [sharafat](solutions/sharafat/8/20.c) - [sadman](solutions/sadman/8/20.c) +- [sharafat](solutions/sharafat/8/20.c) ## Chapter 9 1. Write a program, which reads your name from the keyboard and outputs a list of ASCII codes, which represent your name. +- [sadman](solutions/sadman/9/1.c) - [NAYEMA](solutions/NAYEMA/9/1.c) - [sharafat](solutions/sharafat/9/1.c) -- [sadman](solutions/sadman/9/1.c) 2. Write a program to do the following: ``` @@ -1141,29 +1141,29 @@ Check digit is the remainder when sum is divided by 11. Write a program that rea (d) To output the message ‘try again’, if the answer is wrong. (e) To display the correct answer when the answer is wrong even at the third attempt and stop. ``` +- [sadman](solutions/sadman/9/2.c) - [NAYEMA](solutions/NAYEMA/9/2.c) - [sharafat](solutions/sharafat/9/2.c) -- [sadman](solutions/sadman/9/2.c) 3. Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character. +- [sadman](solutions/sadman/9/3.c) - [NAYEMA](solutions/NAYEMA/9/3.c) - [sharafat](solutions/sharafat/9/3.c) -- [sadman](solutions/sadman/9/3.c) 4. Write a program which will read a text and count all occurrences of a particular word. +- [sadman](solutions/sadman/9/4.c) - [NAYEMA](solutions/NAYEMA/9/4.c) - [sharafat](solutions/sharafat/9/4.c) -- [sadman](solutions/sadman/9/4.c) 5. Write a program which will read a string and rewrite it in the alphabetical order. For example, the word STRING should be written as GINRST. +- [sadman](solutions/sadman/9/5.c) - [NAYEMA](solutions/NAYEMA/9/5.c) - [sharafat](solutions/sharafat/9/5.c) -- [sadman](solutions/sadman/9/5.c) 6. Write a program to replace a particular word by another word in a given string. For example, the word “PASCAL” should be replaced by “C” in the text “It is good to program in PASCAL language.” +- [sadman](solutions/sadman/9/6.c) - [NAYEMA](solutions/NAYEMA/9/6.c) - [sharafat](solutions/sharafat/9/6.c) -- [sadman](solutions/sadman/9/6.c) 7. A Maruti car dealer maintains a record of sales of various vehicles in the following form: @@ -1179,8 +1179,8 @@ Write a program to read this data into a table of strings and output the details - [sadman](solutions/sadman/9/7.c) 8. Write a program that reads a string from the keyboard and determines whether the string is a palindrome or not. (A string is a palindrome if it can be read from left and right with the same meaning. For example, Madam and Anna are palindrome strings. Ignore capitalization). -- [sharafat](solutions/sharafat/9/8.c) - [sadman](solutions/sadman/9/8.c) +- [sharafat](solutions/sharafat/9/8.c) 9. Write program that reads the cost of an item in the form RRRR.PP (Where RRRR denotes Rupees and PP denotes Paise) and converts the value to a string of words that expresses the numeric value in words. For example, if we input 125.75, the output should be “ONE HUNDRED TWENTY FIVE AND PAISE SEVENTY FIVE”. @@ -1199,25 +1199,25 @@ and produce the following output list: (b) List sorted on roll numbers. (c) List sorted on marks (rank-wise list) ``` -- [sharafat](solutions/sharafat/9/10.c) - [sadman](solutions/sadman/9/10.c) +- [sharafat](solutions/sharafat/9/10.c) 11. Write a program to read two strings and compare them using the function strncmp( ) and print a message that the first string is equal, less, or greater than the second one. -- [sharafat](solutions/sharafat/9/11.c) - [sadman](solutions/sadman/9/11.c) +- [sharafat](solutions/sharafat/9/11.c) 12. Write a program to read a line of text from the keyboard and print out the number of occurrences of a given substring using the function strstr ( ). -- [sharafat](solutions/sharafat/9/12.c) - [sadman](solutions/sadman/9/12.c) +- [sharafat](solutions/sharafat/9/12.c) 13. Write a program that will copy m consecutive characters from a string s1 beginning at position n into another string s2. -- [sharafat](solutions/sharafat/9/13.c) - [sadman](solutions/sadman/9/13.c) +- [sharafat](solutions/sharafat/9/13.c) 14. Write a program to create a directory of students with roll numbers. The program should display the roll number for a specified name and vice-versa. -- [sharafat](solutions/sharafat/9/14.c) - [sadman](solutions/sadman/9/14.c) +- [sharafat](solutions/sharafat/9/14.c) 15. Given a string ``` @@ -1231,43 +1231,46 @@ Write a program that displays the following: 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5 ``` -- [sharafat](solutions/sharafat/9/15.c) - [sadman](solutions/sadman/9/15.c) +- [sharafat](solutions/sharafat/9/15.c) 16. Write a C program to compare two strings without using any string function. -- [sharafat](solutions/sharafat/9/16.c) - [sadman](solutions/sadman/9/16.c) +- [sharafat](solutions/sharafat/9/16.c) 17. Write a C program to find the largest and smallest sized word in a string. -- [sharafat](solutions/sharafat/9/17.c) - [sadman](solutions/sadman/9/17.c) +- [sharafat](solutions/sharafat/9/17.c) 18. Write a C program to replace all the white spaces in a string with double white spaces. -- [sharafat](solutions/sharafat/9/18.c) - [sadman](solutions/sadman/9/18.c) +- [sharafat](solutions/sharafat/9/18.c) 19. Write a C program to enter multiple strings and display them in lexicographical order. -- [sharafat](solutions/sharafat/9/19.c) - [sadman](solutions/sadman/9/19.c) +- [sharafat](solutions/sharafat/9/19.c) 20. Write a C program to concatenate two strings without using any string function. -- [sharafat](solutions/sharafat/9/20.c) - [sadman](solutions/sadman/9/20.c) +- [sharafat](solutions/sharafat/9/20.c) ## Chapter 10 1. Write a function exchange to interchange the values of two variables, say x and y. Illustrate the use of this function, in a calling function. Assume that x and y are defined as global variables. - [sadman](solutions/sadman/10/1.c) - [Hridoy](solutions/Hridoy/10/1.c) +- [sharafat](solutions/sharafat/10/1.c) 2. Write a function space(x) that can be used to provide a space of x positions between two output numbers. Demonstrate its application. - [sadman](solutions/sadman/10/2.c) +- [sharafat](solutions/sharafat/10/2.c) 3. Use recursive function calls to evaluate ``` f(x) = x - pow(x,3)/3! + pow(x,5)/5! - pow(x,7)/7! + ..... ``` - [sadman](solutions/sadman/10/3.c) +- [sharafat](solutions/sharafat/10/3.c) 4. An n_order polynomial can be evaluated as follows: ``` @@ -1275,6 +1278,7 @@ Write a program that displays the following: ``` Write a function to evaluate the polynomial, using an array variable. Test it using a main program. - [sadman](solutions/sadman/10/4.c) +- [sharafat](solutions/sharafat/10/4.c) 5. The Fibonacci numbers are defined recursively as follows: ``` @@ -1284,15 +1288,19 @@ Write a function to evaluate the polynomial, using an array variable. Test it us ``` Write a function that will generate and print the first n Fibonacci numbers. Test the function for n = 5, 10, and 15. - [sadman](solutions/sadman/10/5.c) +- [sharafat](solutions/sharafat/10/5.c) 6. Write a function that will round a floating-point number to an indicated decimal place. For example the number 17.457 would yield the value 17.46 when it is rounded off to two decimal places. - [sadman](solutions/sadman/10/6.c) +- [sharafat](solutions/sharafat/10/6.c) 7. Write a function prime that returns 1 if its argument is a prime number and returns zero otherwise. - [sadman](solutions/sadman/10/7.c) +- [sharafat](solutions/sharafat/10/7.c) 8. Write a function that will scan a character string passed as an argument and convert all lowercase characters into their uppercase equivalents. - [sadman](solutions/sadman/10/8.c) +- [sharafat](solutions/sharafat/10/8.c) 9. Develop a top_down modular program to implement a calculator. The program should request the user to input two numbers and display one of the following as per the desire of the user: ``` @@ -1303,6 +1311,7 @@ Write a function that will generate and print the first n Fibonacci numbers. Tes ``` Provide separate functions for performing various tasks such as reading, calculating and displaying. Calculating module should call second level modules to perform the individual mathematical operations. The main function should have only function calls. - [sadman](solutions/sadman/10/9.c) +- [sharafat](solutions/sharafat/10/9.c) 10. Develop a modular interactive program using functions that reads the values of three sides of a triangle and displays either its area or its perimeter as per the request of the user. Given the three sides a, b and c. ``` @@ -1311,12 +1320,15 @@ Provide separate functions for performing various tasks such as reading, calcula where s - (a+b+c)/2 ``` - [sadman](solutions/sadman/10/10.c) +- [sharafat](solutions/sharafat/10/10.c) 11. Write a function that can be called to find the largest element of an m by n matrix. - [sadman](solutions/sadman/10/11.c) +- [sharafat](solutions/sharafat/10/11.c) 12. Write a function that can be called to compute the product of two matrices of size m by n and n by m. The main function provides the values for m and n and two matrices. - [sadman](solutions/sadman/10/12.c) +- [sharafat](solutions/sharafat/10/12.c) 13. Design and code an interactive modular program that will use functions to a matrix of m by n size, @@ -1324,6 +1336,7 @@ compute column averages and row averages, and then print the entire matrix with averages shown in respective rows and columns. - [sadman](solutions/sadman/10/13.c) +- [sharafat](solutions/sharafat/10/13.c) 14. Develop a top-down modular program that will perform the following tasks: ``` @@ -1334,6 +1347,7 @@ respective rows and columns. ``` Use functions for carrying out each of the above tasks. The main function should have only function calls. - [sadman](solutions/sadman/10/14.c) +- [sharafat](solutions/sharafat/10/14.c) 15. Develop your own functions for performing following operations on strings: ``` @@ -1343,6 +1357,7 @@ Use functions for carrying out each of the above tasks. The main function should ``` Write a driver program to test your functions. - [sadman](solutions/sadman/10/15.c) +- [sharafat](solutions/sharafat/10/15.c) 16. Write a program that invokes a function called find( ) to perform the following tasks: @@ -1351,21 +1366,26 @@ find( ) to perform the following tasks: (b) Returns 1 if the specified character is found in the array, 0 otherwise. ``` - [sadman](solutions/sadman/10/16.c) +- [sharafat](solutions/sharafat/10/16.c) 17. Design a function locate ( ) that takes two character arrays s1 and s2 and one integer value m as parameters and inserts the string s2 into s1 immediately after the index m . Write a program to test the function using a real-life situation. (Hint: s2 may be a missing word in s1 that represents a line of text). +- [sharafat](solutions/sharafat/10/17.c) 18. Write a function that takes an integer parameter m representing the month number of the year and returns the corresponding name of the month. For instance, if m = 3, the month is March. Test your program. - [sadman](solutions/sadman/10/18.c) +- [sharafat](solutions/sharafat/10/18.c) 19. In preparing the calendar for a year we need to know whether that particular year is leap year or not. Design a function leap( ) that receives the year as a parameter and returns an appropriate message. What modifications are required if we want to use the function in preparing the actual calendar? - [sadman](solutions/sadman/10/19.c) +- [sharafat](solutions/sharafat/10/19.c) 20. Write a function that receives a floating point value x and returns it as a value rounded to two nearest decimal places. For example, the value 123.4567 will be rounded to 123.46 (Hint: Seek help of one of the math functions available in math library). - [sadman](solutions/sadman/10/20.c) +- [sharafat](solutions/sharafat/10/20.c) ## Chapter 11 From 79d3a59aa58ee50416b0cfd540ac04682eceee2d Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 11 Aug 2023 09:53:43 +0600 Subject: [PATCH 13/19] 11 | 1-2 | sharafat --- solutions/sharafat/11/1.c | 19 +++++++++++++++++++ solutions/sharafat/11/2.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 solutions/sharafat/11/1.c create mode 100644 solutions/sharafat/11/2.c diff --git a/solutions/sharafat/11/1.c b/solutions/sharafat/11/1.c new file mode 100644 index 0000000..5e15f10 --- /dev/null +++ b/solutions/sharafat/11/1.c @@ -0,0 +1,19 @@ +#include + +struct time_struct +{ + int hour; + int minute; + int second; +}; + +int main() +{ + struct time_struct time; + printf("Enter time in HH:MM:SS format: "); + scanf("%d:%d:%d", &time.hour, &time.minute, &time.second); + printf("Equivalent time: "); + + printf("%d:%d:%d\n", time.hour, time.minute, time.second); + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/11/2.c b/solutions/sharafat/11/2.c new file mode 100644 index 0000000..1ec656c --- /dev/null +++ b/solutions/sharafat/11/2.c @@ -0,0 +1,28 @@ +#include + +struct time_struct +{ + int hour; + int minute; + int second; +}; + +void input_time(struct time_struct *time) +{ + printf("Enter time in HH:MM:SS format: "); + scanf("%d:%d:%d", &time->hour, &time->minute, &time->second); +} + +void print_time(struct time_struct time) +{ + printf("Equivalent time: "); + printf("%d:%d:%d\n", time.hour, time.minute, time.second); +} + +int main() +{ + struct time_struct time; + input_time(&time); + print_time(time); + return 0; +} \ No newline at end of file From 14130dfa1d338aae6fd8bf08deded6fe07f83d2d Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 11 Aug 2023 15:10:01 +0600 Subject: [PATCH 14/19] 10 | 1-5 | sharafat --- solutions/sharafat/11/3.c | 51 +++++++++++++++++++++ solutions/sharafat/11/4.c | 48 ++++++++++++++++++++ solutions/sharafat/11/5.c | 94 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 solutions/sharafat/11/3.c create mode 100644 solutions/sharafat/11/4.c create mode 100644 solutions/sharafat/11/5.c diff --git a/solutions/sharafat/11/3.c b/solutions/sharafat/11/3.c new file mode 100644 index 0000000..11bdd93 --- /dev/null +++ b/solutions/sharafat/11/3.c @@ -0,0 +1,51 @@ +#include + +struct time_struct +{ + int hour; + int minute; + int second; +}; + +void input_time(struct time_struct *time) +{ + printf("Enter time in HH:MM:SS format: "); + scanf("%d:%d:%d", &time->hour, &time->minute, &time->second); +} + +void print_time(struct time_struct time) +{ + printf("Equivalent time: "); + printf("%d:%d:%d\n", time.hour, time.minute, time.second); +} + +struct time_struct increment_second_in_time(struct time_struct time) +{ + time.second++; + if (time.second == 60) + { + time.second = 0; + time.minute++; + if (time.minute == 60) + { + time.minute = 0; + time.hour++; + if (time.hour == 24) + { + time.hour = 0; + } + } + } + return time; +} + +int main() +{ + struct time_struct time; + input_time(&time); + print_time(time); + printf("Time after incrementing second: "); + time = increment_second_in_time(time); + print_time(time); + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/11/4.c b/solutions/sharafat/11/4.c new file mode 100644 index 0000000..5dd6e67 --- /dev/null +++ b/solutions/sharafat/11/4.c @@ -0,0 +1,48 @@ +#include +#include + +struct date +{ + int day; + int month; + int year; +}; + +void input_date(struct date *date) +{ + printf("Enter date in DD/MM/YYYY format: "); + scanf("%d/%d/%d", &date->day, &date->month, &date->year); +} + +void validate_data(struct date *date) +{ + if (date->year < 1) + { + printf("Invalid year\n"); + exit(1); + } + if (date->month < 1 || date->month > 12) + { + printf("Invalid month\n"); + exit(1); + } + if ((date->day < 1 || date->day > 31) || (date-> day > 30 && (date->month == 4 || date->month == 6 || date->month == 9 || date->month == 11)) || (date->day > 28 && date->month == 2) || (date->day > 29 && date->month == 2 && (date->year % 4 != 0 || (date->year % 100 == 0 && date->year % 400 != 0)))) + { + printf("Invalid day\n"); + exit(1); + } +} + +void print_date(struct date *date) +{ + printf("Date: %d/%d/%d\n", date->day, date->month, date->year); +} + +int main() +{ + struct date date; + input_date(&date); + validate_data(&date); + print_date(&date); + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/11/5.c b/solutions/sharafat/11/5.c new file mode 100644 index 0000000..845e19d --- /dev/null +++ b/solutions/sharafat/11/5.c @@ -0,0 +1,94 @@ +#include +#include + +struct date +{ + int day; + int month; + int year; +}; + +void input_date(struct date *date) +{ + printf("Enter date in DD/MM/YYYY format: "); + scanf("%d/%d/%d", &date->day, &date->month, &date->year); +} + +void validate_data(struct date *date) +{ + if (date->year < 1) + { + printf("Invalid year\n"); + exit(1); + } + if (date->month < 1 || date->month > 12) + { + printf("Invalid month\n"); + exit(1); + } + if ((date->day < 1 || date->day > 31) || (date-> day > 30 && (date->month == 4 || date->month == 6 || date->month == 9 || date->month == 11)) || (date->day > 28 && date->month == 2) || (date->day > 29 && date->month == 2 && (date->year % 4 != 0 || (date->year % 100 == 0 && date->year % 400 != 0)))) + { + printf("Invalid day\n"); + exit(1); + } +} + +int validate_data_and_return(struct date date) +{ + if (date.year < 1) + { + printf("Invalid year\n"); + return(1); + } + if (date.month < 1 || date.month > 12) + { + printf("Invalid month\n"); + return(1); + } + if ((date.day < 1 || date.day > 31) || (date. day > 30 && (date.month == 4 || date.month == 6 || date.month == 9 || date.month == 11)) || (date.day > 28 && date.month == 2) || (date.day > 29 && date.month == 2 && (date.year % 4 != 0 || (date.year % 100 == 0 && date.year % 400 != 0)))) + { + printf("Invalid day\n"); + return(1); + } + return(0); +} + +void update(struct date *date) +{ + struct date temp_date = *date; + temp_date.day++; + if (validate_data_and_return(temp_date)) + { + temp_date.day = 1; + temp_date.month++; + if (validate_data_and_return(temp_date)) + { + temp_date.month = 1; + temp_date.year++; + if (validate_data_and_return(temp_date)) + { + printf("Invalid date\n"); + exit(1); + } + } + } + *date = temp_date; +} + +void print_date(struct date *date) +{ + printf("Date: %d/%d/%d\n", date->day, date->month, date->year); +} + +int main() +{ + struct date date; + input_date(&date); + validate_data(&date); + print_date(&date); + + printf("Date after incrementing day: \n"); + update(&date); + print_date(&date); + return 0; +} \ No newline at end of file From 9d785b0433991238b2acfc59fc93df8dad8985b7 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 11 Aug 2023 09:10:39 +0000 Subject: [PATCH 15/19] updated logs --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8eb3d32..d0b39e1 100644 --- a/README.md +++ b/README.md @@ -1398,11 +1398,13 @@ and display the time in the following form: 16:40:51 ``` - [sadman](solutions/sadman/11/1.c) +- [sharafat](solutions/sharafat/11/1.c) 2. Modify the above program such that a function is used to input values to the members and another function to display the time. - [sadman](solutions/sadman/11/2.c) +- [sharafat](solutions/sharafat/11/2.c) 3. Design a function *update* that would accept the data structure designed in Exercise 11.1 and @@ -1414,6 +1416,7 @@ member is incremented by one. Then, if the result is the hour member is incremented by one. Finally when the hour becomes 24, it is set to zero.) - [sadman](solutions/sadman/11/3.c) +- [sharafat](solutions/sharafat/11/3.c) 4. Define a structure data type named *date* containing three integer members *day* , *month* , and *year*. Develop an interactive @@ -1433,6 +1436,7 @@ Examples of invalid data: 29, 2, 2002 – 2002 is not a leap year ``` - [sadman](solutions/sadman/11/4.c) +- [sharafat](solutions/sharafat/11/4.c) 5. Design a function *update* that accepts the *date* structure designed in Exercise 11.4 to increment the @@ -1446,6 +1450,7 @@ be incremented (c) There are 29 days in February of a leap year ``` - [sadman](solutions/sadman/11/5.c) +- [sharafat](solutions/sharafat/11/5.c) 6. Modify the input function used in Exercise 11.4 such that it reads a value that represents the date in the From 594832e92ac1d7408249009e3c20447abcb425bb Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 11 Aug 2023 16:55:33 +0600 Subject: [PATCH 16/19] 11 | 7 | sharafat --- solutions/sharafat/11/5.c | 6 +-- solutions/sharafat/11/6.c | 48 +++++++++++++++++ solutions/sharafat/11/7.c | 105 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 solutions/sharafat/11/6.c create mode 100644 solutions/sharafat/11/7.c diff --git a/solutions/sharafat/11/5.c b/solutions/sharafat/11/5.c index 845e19d..19a60c0 100644 --- a/solutions/sharafat/11/5.c +++ b/solutions/sharafat/11/5.c @@ -37,17 +37,17 @@ int validate_data_and_return(struct date date) { if (date.year < 1) { - printf("Invalid year\n"); + // printf("Invalid year\n"); return(1); } if (date.month < 1 || date.month > 12) { - printf("Invalid month\n"); + // printf("Invalid month\n"); return(1); } if ((date.day < 1 || date.day > 31) || (date. day > 30 && (date.month == 4 || date.month == 6 || date.month == 9 || date.month == 11)) || (date.day > 28 && date.month == 2) || (date.day > 29 && date.month == 2 && (date.year % 4 != 0 || (date.year % 100 == 0 && date.year % 400 != 0)))) { - printf("Invalid day\n"); + // printf("Invalid day\n"); return(1); } return(0); diff --git a/solutions/sharafat/11/6.c b/solutions/sharafat/11/6.c new file mode 100644 index 0000000..b799f21 --- /dev/null +++ b/solutions/sharafat/11/6.c @@ -0,0 +1,48 @@ +#include +#include + +struct date +{ + int day; + int month; + int year; +}; + +void input_date(struct date *date) +{ + printf("Enter date in YYYYMMDD format: "); + scanf("%4d%2d%2d", &date->year, &date->month, &date->day); +} + +void validate_data(struct date *date) +{ + if (date->year < 1) + { + printf("Invalid year\n"); + exit(1); + } + if (date->month < 1 || date->month > 12) + { + printf("Invalid month\n"); + exit(1); + } + if ((date->day < 1 || date->day > 31) || (date-> day > 30 && (date->month == 4 || date->month == 6 || date->month == 9 || date->month == 11)) || (date->day > 28 && date->month == 2) || (date->day > 29 && date->month == 2 && (date->year % 4 != 0 || (date->year % 100 == 0 && date->year % 400 != 0)))) + { + printf("Invalid day\n"); + exit(1); + } +} + +void print_date(struct date *date) +{ + printf("Date: %d/%d/%d\n", date->day, date->month, date->year); +} + +int main() +{ + struct date date; + input_date(&date); + validate_data(&date); + print_date(&date); + return 0; +} \ No newline at end of file diff --git a/solutions/sharafat/11/7.c b/solutions/sharafat/11/7.c new file mode 100644 index 0000000..0ae1143 --- /dev/null +++ b/solutions/sharafat/11/7.c @@ -0,0 +1,105 @@ +#include +#include + +struct date +{ + int day; + int month; + int year; +}; + +void input_date(struct date *date) +{ + printf("Enter date in DD/MM/YYYY format: "); + scanf("%d/%d/%d", &date->day, &date->month, &date->year); +} + +void validate_data(struct date *date) +{ + if (date->year < 1) + { + printf("Invalid year\n"); + exit(1); + } + if (date->month < 1 || date->month > 12) + { + printf("Invalid month\n"); + exit(1); + } + if ((date->day < 1 || date->day > 31) || (date-> day > 30 && (date->month == 4 || date->month == 6 || date->month == 9 || date->month == 11)) || (date->day > 28 && date->month == 2) || (date->day > 29 && date->month == 2 && (date->year % 4 != 0 || (date->year % 100 == 0 && date->year % 400 != 0)))) + { + printf("Invalid day\n"); + exit(1); + } +} + +int validate_data_and_return(struct date date) +{ + if (date.year < 1) + { + // printf("Invalid year\n"); + return(1); + } + if (date.month < 1 || date.month > 12) + { + // printf("Invalid month\n"); + return(1); + } + if ((date.day < 1 || date.day > 31) || (date. day > 30 && (date.month == 4 || date.month == 6 || date.month == 9 || date.month == 11)) || (date.day > 28 && date.month == 2) || (date.day > 29 && date.month == 2 && (date.year % 4 != 0 || (date.year % 100 == 0 && date.year % 400 != 0)))) + { + // printf("Invalid day\n"); + return(1); + } + return(0); +} + +void update(struct date *date) +{ + struct date temp_date = *date; + temp_date.day++; + if (validate_data_and_return(temp_date)) + { + temp_date.day = 1; + temp_date.month++; + if (validate_data_and_return(temp_date)) + { + temp_date.month = 1; + temp_date.year++; + if (validate_data_and_return(temp_date)) + { + printf("Invalid date\n"); + exit(1); + } + } + } + *date = temp_date; +} + +void nextdate(struct date *date) +{ + int days_to_add = 1; + printf("Enter number of days to add: "); + scanf("%d", &days_to_add); + for (int i = 0; i < days_to_add; i++) + { + update(date); + } +} + +void print_date(struct date *date) +{ + printf("Date: %d/%d/%d\n", date->day, date->month, date->year); +} + +int main() +{ + struct date date; + input_date(&date); + validate_data(&date); + print_date(&date); + + nextdate(&date); + printf("Date after incrementing day: \n"); + print_date(&date); + return 0; +} \ No newline at end of file From 0edcf1c6d8073ea15e8d5dd3c68fb0091eb34986 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 11 Aug 2023 10:55:51 +0000 Subject: [PATCH 17/19] updated logs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d0b39e1..7a217d8 100644 --- a/README.md +++ b/README.md @@ -1461,6 +1461,7 @@ values to the members day, month , and year. convert the long integer 19450815 into year, month and day. - [sadman](solutions/sadman/11/6.c) +- [sharafat](solutions/sharafat/11/6.c) 7. Add a function called nextdate to the program designed in Exercise 11.4 to perform the following @@ -1476,6 +1477,7 @@ Note that the next date may be in the next month or even the next year. ``` - [sadman](solutions/sadman/11/7.c) +- [sharafat](solutions/sharafat/11/7.c) 8. Use the *date* structure defined in Exercise 11.4 to store two dates. Develop a function that will take From c1478390659566ef854056c1739d332fecbfc4a4 Mon Sep 17 00:00:00 2001 From: SharafatKarim Date: Fri, 11 Aug 2023 17:04:25 +0600 Subject: [PATCH 18/19] 11 | 8 | sharafat --- solutions/sharafat/11/8.c | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 solutions/sharafat/11/8.c diff --git a/solutions/sharafat/11/8.c b/solutions/sharafat/11/8.c new file mode 100644 index 0000000..9ab8ce5 --- /dev/null +++ b/solutions/sharafat/11/8.c @@ -0,0 +1,99 @@ +#include +#include + +struct date +{ + int day; + int month; + int year; +}; + +void input_date(struct date *date) +{ + printf("Enter date in DD/MM/YYYY format: "); + scanf("%d/%d/%d", &date->day, &date->month, &date->year); +} + +void validate_data(struct date *date) +{ + if (date->year < 1) + { + printf("Invalid year\n"); + exit(1); + } + if (date->month < 1 || date->month > 12) + { + printf("Invalid month\n"); + exit(1); + } + if ((date->day < 1 || date->day > 31) || (date-> day > 30 && (date->month == 4 || date->month == 6 || date->month == 9 || date->month == 11)) || (date->day > 28 && date->month == 2) || (date->day > 29 && date->month == 2 && (date->year % 4 != 0 || (date->year % 100 == 0 && date->year % 400 != 0)))) + { + printf("Invalid day\n"); + exit(1); + } +} + +int compare_two_date(struct date *one, struct date *two) +{ + if (one->year > two->year) + { + return(1); + } + else if (one->year < two->year) + { + return(0); + } + else + { + if (one->month > two->month) + { + return(1); + } + else if (one->month < two->month) + { + return(0); + } + else + { + if (one->day > two->day) + { + return(1); + } + else if (one->day < two->day) + { + return(0); + } + else + { + return(0); + } + } + } +} + +void print_date(struct date *date) +{ + printf("Date: %d/%d/%d\n", date->day, date->month, date->year); +} + +int main() +{ + struct date date1, date2; + input_date(&date1); + validate_data(&date1); + + input_date(&date2); + validate_data(&date2); + + if (!compare_two_date(&date1, &date2)) + { + printf("Earlier date: "); + print_date(&date1); + } + else + { + printf("Earlier date: "); + print_date(&date2); + } + return 0; +} \ No newline at end of file From f82107c7e23eac0b99a74431edebe31204c7c4c9 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 11 Aug 2023 11:04:46 +0000 Subject: [PATCH 19/19] updated logs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7a217d8..f889cfa 100644 --- a/README.md +++ b/README.md @@ -1487,6 +1487,7 @@ these two dates as input and compares them. (b) It returns 0, if *date1* is later date ``` - [sadman](solutions/sadman/11/8.c) +- [sharafat](solutions/sharafat/11/8.c) 9. Define a structure to represent a vector (a series of integer values) and write a modular program to