Initial commit
@@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
int value;
|
||||
int iErr;
|
||||
|
||||
printf("Value to examine: ");
|
||||
|
||||
iErr = scanf("%d",&value);
|
||||
|
||||
if(iErr != 1){
|
||||
printf("Unable to read the value\n");
|
||||
return 0;
|
||||
}
|
||||
if(value <= 0) {
|
||||
printf("Value must be positive\n");
|
||||
return 0;
|
||||
}
|
||||
int binaryArray[32];
|
||||
int arrayLength = 0;
|
||||
while(value > 0) {
|
||||
binaryArray[arrayLength] = value % 2;
|
||||
value = value/2;
|
||||
arrayLength++;
|
||||
}
|
||||
int counter = 0;
|
||||
for(int i = arrayLength; i >= 0; i--) {
|
||||
if (binaryArray[i] == 1) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
printf("Number of ones: %d\n", counter);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
int value;
|
||||
int iErr;
|
||||
|
||||
printf("Value to examine: ");
|
||||
|
||||
iErr = scanf("%d",&value);
|
||||
|
||||
if(iErr != 1){
|
||||
printf("Unable to read the value\n");
|
||||
return 0;
|
||||
}
|
||||
if(value <= 0) {
|
||||
printf("Value must be positive\n");
|
||||
return 0;
|
||||
}
|
||||
int binaryArray[32];
|
||||
int arrayLength = 0;
|
||||
while(value > 0) {
|
||||
binaryArray[arrayLength] = value % 2;
|
||||
value = value/2;
|
||||
arrayLength++;
|
||||
}
|
||||
int counter = 0;
|
||||
for(int i = arrayLength; i > 0; i--) {
|
||||
if (binaryArray[i] == 1) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
printf("Number of ones: %d", counter);
|
||||
return 0;
|
||||
}
|
||||