Posts

Showing posts from March, 2021

How two read integer and String in java in Same program

Image
Code: to read integer and string in same program:       if we try to take a integer and after that a string in java it read integer successfully but skip the       next  line  to read the string so we do this in following way.

Program to print Z in Python

Image
 Code: n=int(input('inter size of Z:' )) for i in range(n):     for j in range(n):         if(i==0 or i==n-1 or i+j==n-1):             print('*', end=" ")         else:             print(' ',end=" ")          print('') Output:

program to covert a base 10 number in any base system

Image
 Problem Statement: Given a number in base 10 convert it in base 2, 3, 4,5,.......,9 Code: n=int(input("enter a number with base 10:")) b=int (input("enter the base in which you want to convert:")) p=1 num=0 while(n>0):     rem=n%b     num=rem*p+num     p=p*10     n=n//b print(num) Screansort of code and output:

Jadoo hates Number code in python using ord() function:

Image
  Problem statement : Jadoo hates numbers, but he requires to print a special number "420" to recharge the equation of life. He  asks your help to print the number but Since he hates numbers, he asks you to write the program such  that there would not be any number in the code. Code: print( ord('z')+ ord('h')+ ord('a')+ ord('a')) Explanation: ord() function return Unicode of a symbol  ord('a')=97, ord('h')=104 and ord('z')=122 Scream sort  of output and code

Hacker earth Binary subsequence "01" and "10" Problem Solution:

Image
Problem Statement: Given four number x, y, a and b check if there exists a binary string having x 0's and y 1's such that the total number of subsequence equal to the sequence "01" in it is a and the total number of subsequence equal to the sequence "10" in it is b. Given: A binary string is a string made of the character '0' and '1' only. A sequence a is a subsequence of a sequence b if a can be obtained from b by deletion of several element.  Input Format   The  first line contains a single integer T (1<=T<=10^5), denoting the number of test cases. Each of the next T lines contains four integers x, y, a and b (1<=x, y<=10^5, 0<=a, b<=10^9)                             Sample input:                                                       ...

Program to print a pattern in python

Image
Problem:  Print a pattern of numbers from     to     as shown below. Each of the numbers is separated by a  single space in python                 4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4 Code: n= int(input("enter")) l=n*2-1 for i in range(l): for j in range(l): if(i<j): m=i else: m=j if(m<l- i): m=m else: m=l-i-1 if(m<l-j): m=m el...

Program to calculate Permutation in Python

Image
Program to calculate permutation in python:- def fact(m):     if(m==1 or m==0):         return 1     else:         return (m*fact(int(m)-1)) n=int(input("enter value of n:")) r=int(input("enter value of r:")) if(n>=r and r>=0):     print("Permutation=",int(fact(n)/fact(n-r))) else:     print("Invalid Input") Code Screenshot and output:     output: