// Q.1 Print all even number from 100..
for (let i = 0; i<=100; i++) {
// console.log(i);
if (i % 2 == 0) {
console.log(i);
}
}
👍1
// Q.2 Guessing Correct number by user in loop..
let userInput = prompt("Enter Your Guessed Number: ");
while (userInput != 87) {
userInput = prompt("Enter Your Guessed Number: ");
}
console.log("You Guessed Correct Number 87..");
// Print Fibonacci Series
#include <stdio.h>
int main() {
int i, userInput, fibo, firstNum = 0, secondNum = 1;
printf("Enter a number count to print Fibonacci Series: ");
scanf("%d", &userInput);
for (i=0; i<userInput; i++) {
fibo = firstNum;
firstNum = secondNum + fibo;
secondNum = fibo;
printf("%d\n", fibo);
}
return 0;
}
// Infinite loop in C
// Note:- Don't try for long intervel of time ....
#include <stdio.h>
int main() {
for( int i = 0; ; i++ ) {
printf("%d", i);
}
return 0;
}
Master HTML/CSS for Free!
1. W3Schools - w3schools.com
2. Javatpoint - javatpoint.com/html-tutorial
3. Html - html.com
4. Geeksforgeeks - geeksforgeeks.org/html
5. Developer Mozilla - https://developer.mozilla.org/en-US/
1. W3Schools - w3schools.com
2. Javatpoint - javatpoint.com/html-tutorial
3. Html - html.com
4. Geeksforgeeks - geeksforgeeks.org/html
5. Developer Mozilla - https://developer.mozilla.org/en-US/
# Easy method to find largest number from 4 nuumbers
def largestNum(a, b, c, d):
if a>b:
if a>c:
if a>d:
print(a)
else:
print(d)
else:
if c>d:
print(c)
else:
print(d)
else:
if b>c:
if b>d:
print(b)
else:
print(d)
else:
if c>d:
print(c)
else:
print(d)
x = int(input(""))
y = int(input(""))
z = int(input(""))
m = int(input(""))
fine = largestNum(x, y, z, m)
print(fine)
🔥1
// Print Fibonacci series
import java.util.Scanner;
public class FibonacchiSeries {
public static void main(String[] arg) {
Scanner userInput = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = userInput.nextInt();
int fibbo, firstNum = 0, secondNum = 1;
for(int i=0; i<num; i++) {
fibbo = firstNum;
firstNum = secondNum + fibbo;
secondNum = fibbo;
System.out.println(fibbo);
}
}
}
# Finding factorial using Recursion...
def factorial(n):
if n==0:
return 1
else:
return n*factorial(n-1)
num = int(input("Enter a number: "))
print(factorial(num))
## Armstrong number finder.....
num = input("Enter a number: ")
length = len(num)
summ = 0
for i in range(length):
summ += int(num[i]) ** length
print(summ)
Identifying..
if summ == int(num):
print(f"{num} is an Armstrong Number.")
else:
print(f"{num} is not an Armstrong Number.")
# Question:
# Write a program which will find all such numbers which are divisible by 7
# but are not a multiple of 5, between 2000 and 3200 (both included).
# The numbers obtained should be printed in a comma-separated sequence on a single line.
# i = 2000
list1 = []
for i in range(2000, 3200):
if i%7 == 0:
if i%5 != 0:
list1.append(i)
print(list1)
## Try ….
char = input("Enter Your Name: ")
myDict = {}
for i in char:
myDict[i] = ord(i)
print(myDict)
» Binary To Decimal Convertor «
1.>
2.>
1.>
## using last digit of intiger...
def binary(n):
sum = 0
pow = 0
while n != 0:
n2 = n % 10
n //= 10
sum += (2 ** pow) * n2
pow += 1
return sum
print(binary(int(input("Enter a Binary Number: "))))
2.>
## using string length
def binary(n):
summ = 0
j = 0
i = len(n) - 1
while i >= 0:
summ += (2 ** j) * int(n[i])
j += 1
i -= 1
return summ
print(binary(input("Enter a Binary Digit: ")))
public static int binary(int n) {
int sum = 0, pow = 0;
while(n != 0) {
int n2 = n%10;
n = n / 10;
sum += Math.pow(2, pow)*n2;
pow++;
}
return sum;
}
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Binary Number: ");
int num = sc.nextInt();
System.out.print(binary(num));
}
Same Question using java
CᴏᴅɪɴɢNᴇʀᴅ 💸🐾
public static int binary(int n) { int sum = 0, pow = 0; while(n != 0) { int n2 = n%10; n = n / 10; sum += Math.pow(2, pow)*n2; pow++; } return sum; } public static void…
public static int binaryToDec(int n) {
int sum = 0, j = 0;
int i = String.valueOf(n).length() - 1;
while (i >= 0) {
sum += Math.pow(2, j)*Character.getNumericValue(String.valueOf(n).charAt(i));
j++;
i--;
}
return sum;
}
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter binary Number: ");
int bin = sc.nextInt();
System.out.print(binaryToDec(bin));
}
👍1
Print Hollow Rectangle.>>
Code >>
* * * * *
* *
* *
* * * * *
Code >>
def hollow_pattern(row, col):
for i in range(1, row+1):
for j in range(1, col+1):
if i == 1 or i == row or j == 1 or j == col:
print('* ', end='')
else:
print(' ', end='')
print('')
hollow_pattern(
int(input("Enter the number of row: ")),
int(input("Enter the number of column: "))
)
» Decimal to binary and Binary to decimal convertor... «
import java.util.*;
public class decimaltoBinary {
public static int tobinary(int num) {
int binary = 0, j = 0;
while (num != 0) {
binary += (num % 2) * Math.pow(10, j);
num /= 2;
j++;
}
return binary;
}
public static int todecimal(int num) {
int decimal = 0, j = 0;
while (num !=0) {
int rem = num % 10;
decimal += rem * (int)(Math.pow(2, j));
num /= 10;
j++;
}
return decimal;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Type `0` for Decimal to binary.\nType `1` for Binary to decimal\n\nEnter your choice: ");
int choice = sc.nextInt();
if(choice == 0) {
System.out.print("Enter a decimal number: ");
int num = sc.nextInt();
System.out.println("The binary of " + num + " is " + tobinary(num));
} else if(choice == 1) {
System.out.print("Enter a binary number: ");
int num = sc.nextInt();
System.out.println("The decimal of " + num + " is " + todecimal(num));
} else {
System.out.println("Invalid choice!");
}
}
}