Posts

Showing posts from March, 2021

How to write program 1- 1/3+1/4+1/5......n

 double a=4.0,sum=0.0; // take third term as "a" int n=10;  for(i=1 ;i<=n-2;i++) { sum=sum + 1/a; a++ } System.out.prtinln(1- 1.0/3+sum);

How to print 1,12,123,1234...n using java

 /  common way to write  int a=1,n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { System.out.println(a+","); a=a*10+i; }

How to print 1, 11,111,1111...n using java

 /  common way to write  int a=1,n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { System.out.print(a+" ,"); a=a*10+1; }

How to print 9,99,8,89,7,79....

 /  common way to write  int a=9,n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { if(i%2==1) { System.out.print(a); } else { System.out..print(a*10+9); a--; }}

How to print 99,9,89,8,79,7.. using java

//  common way to write  int a=9,n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { if(i%2==1) { System.out.print(a*10+9); } else { System.out..print(a); a--; }}

How to print 1,2,4,7,11...n using java

 // always focus on the first number and mark the difference pattern //  common way to write  int a=1,n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { System.out.println(a); a=a+i; }

How to print 1,2,3,4...n using java

 // always focus on the first number and mark the difference pattern // common way to write  int a=1,n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { System.out.println(a); a++; } // Short cut way to write int n=10 ;  // n value you can take anything for(int i=1;i<=n;i++) { System.out.println(i); a++; }

How to write series program in java

 1/a 2 + 1/a 3 + 1/a 4 -----n // always focus on first term  then see the difference in first and second term Normal way double a=3.0, b=2.0,sum=0.0;  // "a " value you can take anything int n=10  // n value you can take any thing for(int i=1;i<=n;i++) { sum=sum+ 1/ Math.pow(a,b); b++; } System.out.println(sum); Short cut way double sum=0.0,a=3.0;  // "a" value you can take anything int n=10  // n value you can take any thing for(int i=1;i<=n;i++) { sum=sum+ 1/ Math.pow(a, (i+1)); } System.out.println(sum);

How to write program 1/2+2/3+3/4------n terms

 1/2+2/3+3/4------n terms // always focus on first term  then see the difference in first and second term Normal way double a=1.0, b=2.0,sum=0.0; int n=10  // n value you can take any thing for(int i=1;i<=n;i++) { sum=sum+ a/b; a++; b++; } System.out.println(sum); Short cut way double sum=0.0; int n=10  // n value you can take any thing for(int i=1;i<=n;i++) { sum=sum+ i/(i+1); } System.out.println(sum);

How to display your name 50 times using for-loop in python

 for i in range(50):           print("enter your name")

how to write program in python using for-loop

for i in range(10):            print(i) // i starts from 0 by default and  the loop value increase one by default it will continue upto 9 Ans- 0,1,2,3,4,5,6,7,8,9 // if you want to print 1 to 10 using for loop for i in range (1, 10):            print(1) // first argument is the intial value of loop that is 1 Ans- 1,2,3,4,5,6,7,8,9 //  if u want  to increase the value more then one ,then you have to give the third argument for i in range (1,10,2): print(i) // ans-1,3,5,7,9 the first argument is for intial value  2nd argument is for condition third argument is for increment

Calculate electric bill using python

 #  unit                                    bill in rupee    <100                                     5  per unit <200                                       6 per unit >200                                       8 per unit unit=200 if unit<100 :          bill=unit*5 el if unit<200 :          bill=unit*6 else :         bill=unit * 8 print(" the electric bill is", bill)

Syntax for if-else-if

 if condition :        statement el if condition :        statement el if condition :        statement else :       statement

How to find a character from its ASCII

 a=98 b=chr(a) print(b) Ans- "b"

How to find ASCII number of a character using python

 a="A" b=ord(a) print(b) #Ans= 65

How to input data using python

 # for string input name=input("enter your name") print(name); #  for integer input number=int(input("enter a number")) print(number) # for float input number=float(input("enter a decimal number")) print(number)

To check which number is greater among two number using python

# indentation is very important  a=5 b=6 if a>b:      print(" a is greater") else:    print("b is greater")

How to write if -else program using python

 # Syntax for if-else if condition:         statement else:    statement

How to write swapping two number program using python

a=5 b=6 #before swapping print(a," ",b) a,b=b,a # After swapping print(a," ",b)

How to write simple interest program using python

 p=1000 t=2 r=4 SI=p*t*r/100 print("the simple interest is",SI)

How to add two number using python

a=5 b=6 c=a+b print("the addition is ",c)