GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Placement Papers  >  Aditi Technologies

 Print  |  
Question:  how many times 3 occurs between 3 to 3333



April 04, 2007 15:33:19 #7
 ghasagar   Member Since: April 2007    Total Comments: 3 

RE: how many times 3 occurs between 3 to 3333
 

see if this perl snippet works for you..

print "how many times 3 occurs between 3 to 3333?n answer:n";

my @nums = (3..3333);
foreach  (@nums) {
 my @tmp_counter = ($_ =~ m/3/g);
 $final_count += eval($#tmp_counter+1);
}
print "final : $final_count n";

output :
how many times 3 occurs between 3 to 3333?
 answer:
final : 1336

sagar

     

 

Back To Question