Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/to_be_organized/choco_wrapers_sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::io;
//3 chocolates wrapers will give as chocolate
//this is used to find the total no of choclates retained
fn main()
{
let mut rap:i32=0;
let mut m=String::new();
io::stdin()
.read_line(&mut m)
.expect("failed to read from stdin");

let mut n = m.trim()
.parse::<i32>()
.unwrap();
let mut tot:i32=n;
while n>2
{
tot=tot+n/3;
rap=n-n/3*3+n/3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formula simplifies to
n/3

Please check again if the logic is correct.

n=rap;
}
println!("no of chocolates={}",tot);
print!("no of wrapers={}",rap);
}