Skip to content

prog-1/for-loops

Repository files navigation

for loops

Power of 2 (6 points)

(Implement a program in the directory power-of-2)

A user provides an integer n as an input. Write a program that determines if n is a power of 2. In this case, print the power value.

Examples:

The program determines if a number is a power of 2.
Enter the number: 8
8 = 2^3
The program determines if a number is a power of 2.
Enter the number: 6
6 is not a power of 2.

Power of k (6 points)

(Implement a program in the directory power-of-k)

A user provides two integers n and k as an input. Write a program that determins if n is a power of k. In this case, print the power value.

Examples:

The program determines if a number n is a power of k.
Enter n and k: 64 4
64 = 4^3
The program determines if a number n is a power of k.
Enter n and k: 64 8
64 = 8^2
The program determines if a number n is a power of k.
Enter n and k: 9 2
9 is not a power of 2.

Prime number (6 points)

(Implement a program in the directory prime-number)

A user provides an integer n as an input. Write a program that determinees if n is a prime number.

Examples:

The program determines if an integer is prime.
Enter the number: 2
2 is a prime number.
The program determines if an integer is prime.
Enter the number: 4
4 is not a prime number.

Perfect square (6 points)

(Implement a program in the directory perfect-square)

A user provides an integer n as an input. Write a program that determines if n is a perfect square, i.e. there exists an integer k, such that k^2 = N. The program must print k, if n is a perfect square.

Examples:

The program determines if an integer is a perfect square.
Enter the number: 9
9 is a perfect square. 3^2 = 9
The program determines if an integer is a perfect square.
Enter the number: 8
8 is not a perfect square.

First digit (8 points)

(Implement a program in the directory first-digit)

A user provides an integer as an input. Write a program that prints the first digit of the number.

Examples:

The program prints the first digit of the given integer.
Enter the number: 2147
The first digit is 2
The program prints the first digit of the given integer.
Enter the number: 0
The first digit is 0

Reversed number (8 points)

(Implement a program in the directory reversed-number)

A user provides an integer as an input. Write a program that reverses the digits in the integer.

Examples:

The program reverses the digits in the number.
Enter the number: 123
The reversed number is 321
The program reverses the digits in the number.
Enter the number: 1
The reversed number is 1

Even digits (8 points)

(Implement a program in the directory even-digits)

A user provides an integer as an input. Write a program that determines if all digits in the integer are even.

Examples:

The program determines if all digits in the integer are even.
Enter the number: 2860
All digits in 2860 are even.
The program determines if all digits in the integer are even.
Enter the number: 2816
Not all digits in 2816 are even.

About

Assignments on the topic for-loops

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published