-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a C program to check if a number is power of 2
This is writen as a one line-function of course.
- Loading branch information
1 parent
8f98c5d
commit a6ccf31
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,3 +439,8 @@ Name: [Antonio](https://github.com/toluwalope19) </br> | |
Place: Nigeria </br> | ||
Coding Experience: Python and javaScript. </br> | ||
Email: [email protected] </br> | ||
|
||
Name: [Nasser](https://github.com/nasafix-nasser) </br> | ||
Place: Iran </br> | ||
Coding Experience: C/C++. </br> | ||
Email: [email protected] </br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void is_powerof_2(int x) | ||
{ | ||
for(int p = 1; p < x ; p *= 2, printf("%s%s", p == x ? "Yes\n" : "", p > x && x > 1 ? "No\n" : "")); | ||
} | ||
|
||
int main ( int argc, char *argv[] ) | ||
{ | ||
int value; | ||
do { | ||
printf("Enter a number > 1: "); | ||
scanf("%d", &value); | ||
}while(value <= 1); | ||
is_powerof_2(value); | ||
return EXIT_SUCCESS; | ||
} |