Write a program that takes from the user a string that contains digit characters and dots. Your program should then chec

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a program that takes from the user a string that contains digit characters and dots. Your program should then chec

Post by answerhappygod »

Write A Program That Takes From The User A String That Contains Digit Characters And Dots Your Program Should Then Chec 1
Write A Program That Takes From The User A String That Contains Digit Characters And Dots Your Program Should Then Chec 1 (388.75 KiB) Viewed 17 times
Need code in C.
Write a program that takes from the user a string that contains digit characters and dots. Your program should then check the following: 1. If the string has more than one dot (.) output -1. 2. Else if the string has no dots at all, output 0. 3. Else, output the sum of all the digits represented by the characters that occur before the dot. Example 1: Input: 14321.345711 Output: 11 Explanation: The characters that occur before the dot are '1', '4', '3', '2', '1' and they represent numbers 1,4,3,2 and 1 respectively. Their sum is 11. Example 2: Input: 65432 Output: 0 Explanation: The given string does not have any dots at all. So the output is O as per the problem statement. Example 3: Input: 6543.21111.34321 Output: -1 Explanation: The string has more than 1 dot and therefore the output is -1. Constraint: Assume that the input string will never be longer than 1000 characters. Hint: You may need to lookup the ascii values of characters to solve this.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply