Senior Software Development Engineer Interview Report
- -1of 1 vote
Answersfind count of number between 0 to n number equal 2 in Golang
- yeshwanthchowdaryjampala.dr November 30, 2022 in India for 6| Report Duplicate | Flag | PURGE
Senior Software Development Engineer - 0of 0 votes
AnswersNumber of occurrences of 2 as a digit in numbers from 0 to n
- yeshwanthchowdaryjampala.dr November 30, 2022 in India for 6
tell me the answer:
package main
import "fmt"
//var count int
func number(n int, d int) int {
count := 0
itr := d
for itr <= n {
if itr%10 == d {
count += 1
if itr != 0 && itr/10 == d {
count += 1
itr += 1
}
} else if itr/10 == d-1 {
itr = itr + (10 - d)
} else {
itr = itr + 10
}
}
return count
}
func main() {
//count << number(n, d)
//count := number(n, d)
fmt.Println(number(25, 2))
//fmt.Println(number(25, 2))
}| Report Duplicate | Flag | PURGE
Senior Software Development Engineer golang code
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.