- Get link
- X
- Other Apps
Posts
How to print 1,2,3,4...n using java
- Get link
- X
- Other Apps
// 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
- Get link
- X
- Other Apps
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
- Get link
- X
- Other Apps
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
- Get link
- X
- Other Apps
how to write program in python using for-loop
- Get link
- X
- Other Apps
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
To check which number is greater among two number using python
- Get link
- X
- Other Apps