Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions arm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::io;
fn main() {
println!("Enter a Number: ");
let mut num = String::new();
io::stdin()
.read_line(&mut num)
.expect("Error reading number");
let mut n = num.trim()
.parse::<u32>()
.unwrap();
let t=n;
let mut r;
let mut s=0;
while n>0
{
r=n%10;
s=s+r*r*r;
n=n/10;
}
if s==t {
println!("{} is an armstrong number",s);
}
else {
println!("{} is not an a armstrong number",s);
}
}
28 changes: 28 additions & 0 deletions prime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::io;
fn main() {
println!("Enter a Number: ");
let mut num = String::new();
io::stdin()
.read_line(&mut num)
.expect("Error reading number");
let mut n = num.trim()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove mut.

mut is used to allow changing the value of variable. Do not use it unless required to change value dynamically in program after initialization.

.parse::<u32>()
.unwrap();

let mut c=0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

removed assigned 0. This value is replaced in Line 15.

replace with let mut c;

for i in 1..n+1
{
c=0;
for j in 1..i+1
{
if i%j==0
{
c=c+1;
}
}
if(c==2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove parenthesis from if

{
println!("{}",i);
}
}
}