Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infinity loop demonstration #76

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
Empty file added asta.txt
Empty file.
14 changes: 14 additions & 0 deletions src/sum of digits in number
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main(){
let x = 234;
let a = x%10;
println!("a={}",a);
let aa = x/10;
let s = aa%10;
println!("s={}",s);
let ss = aa/10;
let d = ss%10;
println!("d={}",d);
let f = a+s+d;
println!("the sum is ={}",f);

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Please use loops to find sum of digits. The length of number can change and this program is hardcodded for exactly three digits
  2. It looks like similar program already exist in repository https://github.com/rustindia/Rust-for-undergrads/blob/master/src/algorithms_data_structures/simple_algorithms/sum_of_digits.rs

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main(){
let mut x=0;

loop{
x += 5;
if x==100{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this if condition to make it infinite loop

break;
}
println!("the value of x ={}",x);
}
}