Page 1 of 1

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

Posted: Thu Jun 02, 2022 8:16 am
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 18 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.