Private Sub Check_Click()
Dim d As Integer
Dim num As Integer
Dim s As Integer
Dim old As Integer
num = Val(Text1.Text)
old = num
s = 0
While num > 0
d = num Mod 10
s = s + (d * d * d)
num = num \ 10
Wend
If old = s Then
Label1.Caption = "Armstrong"
Else
Label1.Caption = "Not armstrong"
End If
End Sub
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
write a vb program to find the magic square
Write a program to find the grade obtained by the students of a class
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
/*Program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int n = num; //use to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } }
k
no thanks
You can use the Math.sqrt() method.
An Armstrong number (or narcissistic number) for a given number of digits is a number that is equal to the sum of its own digits raised to the power of the number of digits. Here’s a simple Visual Basic 10 program that checks for Armstrong numbers: Module ArmstrongNumber Sub Main() Dim num As Integer Dim sum As Integer = 0 Console.Write("Enter a number: ") num = Convert.ToInt32(Console.ReadLine()) Dim temp As Integer = num Dim digits As Integer = num.ToString().Length While temp > 0 Dim digit As Integer = temp Mod 10 sum += Math.Pow(digit, digits) temp \= 10 End While If sum = num Then Console.WriteLine(num & " is an Armstrong number.") Else Console.WriteLine(num & " is not an Armstrong number.") End If End Sub End Module This program takes a number as input, calculates the sum of its digits raised to the power of the number of digits, and checks if the sum equals the original number.
Yes, do write, or if you're too lazy to your homework, use google.
Write your own prime number program and find out.
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
write a vb program to find the magic square
For first find an example program.
Write a program to find the grade obtained by the students of a class
Yes, do write. That's what you always have to do when you have got a homework-program.
Write a C program called MonthDays to find the number of days in a given month Test your code with different input values to demonstrate that your function is robust?