pratian technologies
Company
Programming
Arrays
write a programming logic to generate to the series: 1,1,2,12,14,26,40,264,304,568...
Read Solution (Total 33)
-
- import java.util.Scanner;
class test{
public static void main(String[] ards){
int a = 1;
int b = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the limit of the sequence:");
int n = sc.nextInt();
int c=1;
for(int i = 0; i < n; i++){
if(i < 2)
System.out.println(a);
else
{
c = a +b;
if((i+1)%4 == 0)
c *= 4;
System.out.println(c);
a = b;
b = c;
}
}
}
}
- 8 years agoHelpfull: Yes(53) No(0)
- first find the series.. which is a bit confusing.
The series comes like this " 1,1,2,12,14.. " where 1+1=2 =>i+j=2 where i and j are initialized as 1 and the result in a separate variable. in a similar way we need to consider to add the "j" values and the "ans" values so as to get the next number of the series. Once we get an answer which is a factor of 3, We need to multiply the result by 4.
1
1
(1+1)=2 ////
(1+2)=3 // (which is a modulus of 3)// hence multiply by 4. which is equal to= 3*4=12 which is the fourth number of the series. => ans = 12
Now, j=2, ans= 12.
(2+12)=14 // (j=12, ans= 14)// now add both for next number of the series
(12+14)= 26 // (6th number in series)
(14+26)= 40
(26+40)= 66 => which is a factor of 3, so multiply by 4 => 4*66 =264= ans
(40+264) => 304.. and goes on
The code logic goes here
{
print ("Hello ");
int i=1,j=1,ans=1;
print (i);
for(int k=0;k - 8 years agoHelpfull: Yes(49) No(6)
- #include
#include
void main()
{
int a=1,b=1,c,i,n;
printf("enter n value ");
scanf("%d",&n);
for(i=0;i - 8 years agoHelpfull: Yes(12) No(5)
- a=1;
b=1;
for(int i=3;i - 8 years agoHelpfull: Yes(11) No(11)
- class Series{
public static void main(String[] ards){
int a = 1;
int b = 1;
int c=1,n=10;
for(int i = 1; i < n; i++){
if(i < 2)
System.out.print(i+" "+b);
else
{
c = a +b;
if((i+1)%4 == 0)
c *= 4;
System.out.print(" "+c);
a = b;
b = c;
}
}
}
} - 8 years agoHelpfull: Yes(10) No(0)
- 1+1 = 2
(1+2)*4 =12
2+12 = 14
12+14 = 26
14+26= 40
(26+40)*4= 264
40+264= 304
264+304 = 568
(304+568)*4 = 3488 - 8 years agoHelpfull: Yes(7) No(2)
- public static void main(String[] args) {
int i=1,j=1,k=0;
System.out.println(i);
while(i - 8 years agoHelpfull: Yes(6) No(9)
- public class Shiyas{
public static void main(String args[])
{
int n1=1,n2=1,n3,i,count=10,c=3,a=4;
System.out.print(n1+" "+n2);//printing 0 and 1
for(i=2;i - 8 years agoHelpfull: Yes(5) No(1)
- import java.util.Scanner;
public class Series {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("Enter range");
int n = scn.nextInt();
int a = 1;
int b = 2;
int c;
System.out.print(a+" "+a+" "+b+" " );
for(int i = 3;i - 8 years agoHelpfull: Yes(5) No(1)
- //
int main() {
// 1,1,2,12,14,26,40,264,304,568...
int x=1;
int y=1;
int n=500;
int z;
printf("%d %d t",x,y);
while(n>z){
z=x+y;
if(z%3==0) z=z*4;
printf("%d t", z);
x=y;
y=z;
}
} - 7 years agoHelpfull: Yes(5) No(0)
- series is like-1,1,2,12,14,40,l264,304,568.............
#include
#include
void series(int,int);
int main()
{
int a=1;
int b=1;
int c=0,d=0,n=0;
printf("%dt%dt",a,b);
series(1,1);
return 0;
}
void series(a,b)
{
while(b - 7 years agoHelpfull: Yes(4) No(6)
- class Aaaa
{
public static void main(String[] args)
{
System.out.println("Hello ");
int i=1,j=1,don=1;
System.out.println(i);
for(int k=0;k - 8 years agoHelpfull: Yes(2) No(1)
- 872
8+4=2 -> 1 is carry
6+1 carry=7
5+3=8
total ans=872 - 8 years agoHelpfull: Yes(2) No(0)
- import java.io.*;
import java.math.*;
import java.util.Arrays;
class SeriesYatin {
public static void main(String args[])
{
int a[]= new int[20];
a[0]=1;
a[1]=1;
int k=1;
for(int i =2;i - 7 years agoHelpfull: Yes(2) No(0)
- void main()
{
int n,i,s=0;
scanf("%d",&n);
for(i=0;i - 7 years agoHelpfull: Yes(1) No(0)
- import java.util.Scanner;
public class prg2
{
static Boolean prime(int p)
{
for(int i=2; i - 7 years agoHelpfull: Yes(1) No(1)
- # Pratian technology interview question
# write code for given series
# 1,1,2,12,14,26,40,264,304
"""
Series logic
initialise i=j=1
iterate and add i,j
in case j is divisible by 3 , multiple j by 4
thus
1
1
1+1=2
1+2=3 // so multiply 4
j=3*4=12
2+12=14
12+14=26
14+26=40
26+40=66 // so multiply 4
j=66*4=264
40+264=304
.....
"""
# code starts
def series(times):
if times==0:
print("No series")
elif times==1:
print("1")
else:
print("1")
print("1")
i=j=1
for c in range(times-2):
temp=i+j
if temp%3==0:
temp=4*temp
i=j
j=temp
# print j
print(j)
times=int(input())
series(times) - 7 years agoHelpfull: Yes(1) No(0)
- public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int a[] = new int[num];
for (int i=0;i1){
a[i] = a[i-1]+a[i-2];
//System.out.println((i+1)+" "+a[i]);
}
else {
a[i]=1;
//System.out.println((i+1)+" "+a[i]);
}
}
for (int arr : a){
System.out.print(arr+",");
}
} - 7 years agoHelpfull: Yes(1) No(0)
- public class MyClass {
public static void main(String args[]) {
int a=1,b=1;
int d=0;
System.out.print(a+","+b+",");
for(int i=1;i - 7 years agoHelpfull: Yes(1) No(0)
- /* Write a program to print following Sequence.
1,1,2,12,14,26,40,264,,304,568...
*/
import java.util.Scanner;
class Series1{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter last number of sequence:");
int n = scan.nextInt();
int first= 1, second= 1, result= 0;
for(int i=1; i - 8 years agoHelpfull: Yes(0) No(2)
- class test{
public static void main(String[] ards){
int a = 1;
int b = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the limit of the sequence:");
int n = sc.nextInt();
int c=1;
for(int i = 0; i < n; i++){
if(i < 2)
System.out.println(a);
else
{
c = a +b;
if((i+1)%4 == 0)
c *= 4;
System.out.println(c);
a=b;
b=c;
}
}
}
} - 7 years agoHelpfull: Yes(0) No(1)
- /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import java.util.*;
import java.util.Scanner;
public class series {
public static void main(String[] args) {
int a=1;
int b=1;
int c;
System.out.print(a+","+b+",");
c=a+b;
for(int i=2;i - 7 years agoHelpfull: Yes(0) No(0)
- 872
it is firstly digit mix with numbers then add previous again add previous and again add previous. - 7 years agoHelpfull: Yes(0) No(0)
- import java.util.Scanner;
public class Pratian1 {
public static void main(String[] args) {
int i,a,b,c,n;
System.out.println("no of elements in series to be printed");
Scanner scan=new Scanner(System.in);
n = scan.nextInt();
a=1;
scan.close();
a=1;
b=0;
for(i=0;i - 7 years agoHelpfull: Yes(0) No(0)
- import java.util.Scanner;
class Series{
public static void main(String args[])
{
int n=10;
int a[]={1,1};
for(int i=0;i - 7 years agoHelpfull: Yes(0) No(0)
- class Test1{
public static void main(String args[]){
int start = 1;
int next = 1;
int n;
for(int i=1; i - 7 years agoHelpfull: Yes(0) No(1)
- #include
#include
#include
void main()
{
int n;
printf("enter the numbern");
scanf("%d",&n);
int n1=1;
int n2=1;
int i;
int next;
int next1;
int next2;
int next3;
int next4;
int next5;
for(i=0;i - 7 years agoHelpfull: Yes(0) No(1)
- a = 1;
b = 1;
n=int(input("Enter the limit of the sequence:"));
c=1;
for i in range(0,n):
if i < 2:
print(a)
else:
c = a +b;
if(i+1)%4 == 0:
c *= 4;
print(c);
a = b;
b = c; - 7 years agoHelpfull: Yes(0) No(0)
- if((i+1)%4 == 0) I dint get through this step...plz anyone help me
- 7 years agoHelpfull: Yes(0) No(0)
- package javasorting;
import java.util.Scanner;
public class SpecialSeries2 {
public static void main(String[] args) {
double a=1;
Scanner kb= new Scanner(System.in);
System.out.println("Enter size of a series");
int sizeOfSeries =kb.nextInt();
System.out.print((int)a+" ");
int count=1;
for(int i=1;i - 6 years agoHelpfull: Yes(0) No(0)
- #include
main()
{
int i=1,n,j=1,res,ans;
printf("nEnter number of terms:");
scanf("%d",&n);
res=i+j;
printf("%dt%dt%dt",i,j,res);
for(i=1;i - 6 years agoHelpfull: Yes(0) No(1)
- #include
int main()
{
int i,j,t1=1,t2=1,t3,n;
printf("Enter the number of terms : ");
scanf("%d",&n);
printf("nThe series is : ");
printf("%d %d ",t1,t2);
for(i=3;i - 6 years agoHelpfull: Yes(0) No(0)
- package p2;
import java.util.Scanner;
public class Sequence2 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
System.out.print("1"+" ");
System.out.print("1"+" ");
int a,b,c;
a=1;
b=1;
for(int i=1;i - 5 years agoHelpfull: Yes(0) No(0)
pratian technologies Other Question
2, 3, 5, 11, 23, 29, 41, 53, 83, 89, 113, 131.......
write a program to generate the follow 1, -2, 6, -15, 31, -56,....N