20 Nickels in a Dollar
import java.math.*; import java.util.*; class AutomorphicNumber{ static int d=10; public static void main(String args[]){ System.out.print("Enter any number :"); Scanner input=new Scanner(System.in); int n=input.nextInt(); if(d>=n){ if ((n*n) % d == n){ System.out.println("Automorphic Number"); } else{ System.out.println("Not Automorphic Number"); } } else if(d<=n){ d=d*10; if ((n*n) %d==n){ System.out.println("Automorphic Number"); } else{ System.out.println("not an automorphic number"); } } } }
#include <stdio.h> int main() { printf("Program to find ODD or Even Number\n"); while(1) { int n = 0; printf("\nEnter a number(-1 for Exit): "); scanf("%d",&n); if( n 0) { printf("%d is a EVEN number.\n", n); } else { printf("%d is a ODD number.\n", n); } } return 0; }
1. Input number, n 2. a = 0 3. d = n % 10 4. Print d 5. a = a + d 6. n = n / 10 7. If n > 0 then goto 3 8. Print a
Sum = n/2[2Xa1+(n-1)d] where n is last number, a1 is the first number & d is the common difference between the numbers, here d=2 for the even /odd numbers. Sum = n/2 [2Xa1+(n-1)2]
1/2*(n2-3n) = number of diagonals 1/2*(202-60) = 170 diagonals
20 Nickels in a Dollar
/* a number divisible by x should be a multiple of x */ int i, n,x; scanf ("%d", &n); scanf ("%d",&x); for(i=x;i =< n;i+=x) { printf ("%d", x); }
The phrase '8 times a number n' just means '8 times n', which can be modeled as 8 x n or 8n.
20 numbers on a dartboard
20% of n = .2 * n, where n is a number.
1
1/2*(n2-3n) = number of diagonals 1/2*(202-60) = 170 diagonals
Let the unknown number be n.Then 20 + n = 30 : Subtract 20 from both sides gives :-20 - 20 + n = 30 - 20 : n = 10
20% of a number, n, is equal to 3. 0.20 * n = 3 n = 3 / 0.20 = 15 20% of 15 is 3.
Suppose the number is n/d. Then n/d >= d => n <= d2 if d < 0 or n >= d2 if d > 0.
In mathematical terms the problem is :- 3n + 6 = 20 + n 3n - n = 20 - 6 2n = 14 n = 7