Pratian technologies
Company
Programming
Program
write a program to generate the following series.Accept the limit upto which the series needs to be generated.
1, -2, 6, -15, 31, -56,....N
Read Solution (Total 35)
-
- //logic is very simple..
//1, 1 + 1^2 = 2, 2 + 2^2 = 6, 6 + 3^2 = 15, 15 + 4^2 = 31, 31 + 5^2 = 56, 56 + 6^2 = 92
class number
{
public static void main(String[] args)
{
System.out.println("started!");
int n1=1,temp;
System.out.println(1);
for (int i=1;i - 9 years agoHelpfull: Yes(90) No(4)
- Scanner sc=new Scanner(System.in);
System.out.println("Enter the N value: ");
int N=sc.nextInt();
int sum = 1;int temp;
for(int i=0;i - 9 years agoHelpfull: Yes(40) No(7)
- int n = 10;
int k = 1;
DataInputStream dataInputStream = new DataInputStream(System.in);
n = dataInputStream.readInt();
System.out.print(1 + ",");
for (int i = 1; i < n; i++) {
k = k + (i * i);
if (i % 2 == 0) {
System.out.print(k + ",");
} else {
System.out.print(-k + ",");
}
}
take n from user !! - 9 years agoHelpfull: Yes(24) No(6)
- int i=1,n,j=1;
printf("Enter term no: ");
scanf("%d",&n);
while(j - 9 years agoHelpfull: Yes(22) No(6)
- int k = 1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the N value: ");
int N=sc.nextInt();
int sum = 1;
int temp;
System.out.print(1 + ",");
for (int i = 1; i < N; i++) {
k = k + (i * i);
if (i % 2 == 0) {
System.out.print(k + ",");
} else {
System.out.print(-k + ","); - 9 years agoHelpfull: Yes(13) No(4)
public static void main(String[] args) throws IOException {
int n = 10;
int k = 1;
DataInputStream dataInputStream = new DataInputStream(System.in);
n = dataInputStream.readInt() ;
System.out.print(1 + ",");
for (int i = 1; i < n; i++) {
k = k + (i * i);
if (i % 2 == 0) {
System.out.print(k + ",");
} else {
System.out.print(-k + ",");
}
}
}
}- 8 years agoHelpfull: Yes(5) No(0)
- logic is: 1+(1*1)=2,
2+(2*2)=6,
6+(3*3+=15.............and so on
#include
void main()
{
int i,j=1,n,a=1;
clrscr();
printf("enter a limit:");
scanf("%d",&n);
printf("the required series is n %dt",a);
for(i=1;i - 8 years agoHelpfull: Yes(5) No(1)
- int i=1,n,j=1;
printf("Enter term no: ");
scanf("%d",&n);
while(j - 9 years agoHelpfull: Yes(4) No(2)
- public class Series_New
{
public static void main(String[] args)
{
int sum=1;
System.out.println("Enter The N");
Scanner sc=new Scanner(System.in);
int N=Integer.parseInt(sc.nextLine());
for(int i=0;i - 9 years agoHelpfull: Yes(3) No(1)
- import java.util.Scanner;
public class Series3 {
public static void main(String args[]) {
int i,a,n,temp =1;
System.out.println("Enter the number of terms upto which want to print the series:");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(i=0; i - 9 years agoHelpfull: Yes(2) No(2)
- //1,-2,6,-15...........
import java.util.Scanner;
public class qus1
{
public static void main(String argc[])
{
Scanner sc=new Scanner(System.in);
int n,i,res=1;
System.out.print("Enter number n : ");
n=sc.nextInt();
System.out.print(res);
for(i=1;i - 8 years agoHelpfull: Yes(2) No(0)
- /*
write a program to generate the following series.
1, -2, 6, -15, 31, -56,....
*/
import java.util.Scanner;
class Series2{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter limit of sequence:");
int n = scan.nextInt();
int first = 1, result = 0;
for(int i = 0; i < n; i++){
result = first + (i*i);
if(i%2 != 0)
System.out.print((-result) + " ");
else
System.out.print(result + " ");
first = result;
}
}
} - 8 years agoHelpfull: Yes(2) No(1)
- int N, k=2, res = 1;
N = Convert.ToInt32( Console.ReadLine( ) );
for( int i = 1; i - 9 years agoHelpfull: Yes(1) No(0)
- int pepper =1 ;
int i , j, limit ;
printf ("Enter the limit value : ") ;
scanf ("%d", &limit ) ;
for (i=1 , j=1 ; i < limit ; j++ )
{
printf ("%d, " ( j%2 ) ? i : -i ) ;
i += pepper ;
pepper = pow ( j , 2 ) ;
} - 9 years agoHelpfull: Yes(1) No(1)
- import java.util.Scanner;
public class B {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Enter How Many Number You Want... ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int sum =1;
int result =1;
for (int i = 1; i - 8 years agoHelpfull: Yes(1) No(0)
- import java.util.*;
public class amitraj {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
int b=a.nextInt();
int l=0;
int o=1;
System.out.println(o);
for(int k=1;k - 8 years agoHelpfull: Yes(1) No(2)
- import java.util.Scanner;
public class Series {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
System.out.println("Enter range");
int n = scn.nextInt();
int a = 1;
int count = 0;
for(int i = 1;count - 8 years agoHelpfull: Yes(1) No(0)
- #include
int main()
{
int i,k=1,n;
printf("Enter the number of terms : ");
scanf("%d",&n);
printf("1 , ");
for (i = 1; i < n; i++)
{
k = k+(i*i);
if (i % 2 == 0)
printf("%d ,",k);
else
printf("%d ,",-k);
}
return 0;
} - 6 years agoHelpfull: Yes(1) No(0)
- public class Series {
public static void main(String[] args) {
int n = 50;
int num=0,j;
int ser = 1;
for(int i=1;i - 9 years agoHelpfull: Yes(0) No(0)
- for(int i=1;i
- 9 years agoHelpfull: Yes(0) No(2)
- int n=1;
for (int i=0;i - 9 years agoHelpfull: Yes(0) No(0)
- int pepper =1 ;
int i , j, limit ;
printf ("Enter the limit value : ");
scanf ("%d", &limit ) ;
for (i=0 , j=0 ; i < limit ; j++ )
{
printf ("%d, " (j%2)? i : -i ) ;
i += pepper ;
pepper = pow( pepper+1 , 2 ) ;
}
- 9 years agoHelpfull: Yes(0) No(3)
- x=0,f=1,k=1
for(i=1,i - 9 years agoHelpfull: Yes(0) No(0)
- class Test1{
public static void main(String[]args){
int n=Integer.parseInt(args[0]);
int s=1;
System.out.print(s);
for(int i=1;i - 9 years agoHelpfull: Yes(0) No(0)
- #include
int main()
{
int sum=1;
for(int i=0;i - 9 years agoHelpfull: Yes(0) No(1)
- #include
#include
void main()
{
int i,n;
printf("Enter the no of termsn");
scanf("%d",&n);
int k=1;
printf("%dt",1);
for(i=1;i - 7 years agoHelpfull: Yes(0) No(0)
- #include
#include
int main()
{
int a=1,b=0,i=1,p[10];
p[0]=a;
while(i - 7 years agoHelpfull: Yes(0) No(0)
- package Series;
/////1,-2,6,-15,31,-56,....N
public class SeriesA {
public static void main(String[] args) {
//int n;
int f1 = 1;
for(int i=1;i - 7 years agoHelpfull: Yes(0) No(0)
- #include
int main(){
int sum=0,n,sum1=2;
scanf("%d",&n);
for(int i=2;sum1 - 7 years agoHelpfull: Yes(0) No(0)
- import Java.util.scanner;
class Test1
{
Public static void main(string [] args)
{
int k=1;
Scanner s= new Scanner(System.in);
System.out.print("Enter the N value:");
int n= s.nextInt();
System.out.print(1+",");
for(int i = 1;i - 7 years agoHelpfull: Yes(0) No(0)
- //developer ruhul amin choudhury
//time : 04:46 AM
#include
#include
int main()
{
int end_term , ans = 1 , i ;
scanf("%d",&end_term);
if(end_term == 1)
printf("1n);
else
{
printf("1 ") ;
for(i = 1 ; i < end_term ; i++)
{
if( (i+1) < 4)
ans = i + ( i * i ) ; // for 1 -2 6 values
else
ans = ans + (i * i ) ; // for -15 31 -56 to .... end terms or last term
if( i %2 != 0 )
printf(" - %d " ,ans);
else
printf("%d " ,ans );
}
}
return 0 ;
} - 7 years agoHelpfull: Yes(0) No(0)
- class Test1{
public static void main(String args[]){
int start=1;
System.out.print(start+"t");
int a=1;
for(int i=1; i - 7 years agoHelpfull: Yes(0) No(0)
- this code works
#include
int main()
{
int n=10,k=1,i;
printf("Enter n : ");
scanf("%d",&n);
for(i=0;i - 6 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
int main()
{
int i,k=1,n;
printf("Enter the number of terms : ");
scanf("%d",&n);
printf("1 , ");
for (i = 1; i < n; i++)
{
k = k+(i*i);
if (i % 2 == 0)
printf("%d ,",k);
else
printf("%d ,",-k);
}
return 0;
} - 6 years agoHelpfull: Yes(0) No(0)
Pratian technologies Other Question
optimize the code by applying the following logic.
The LCM for 2,3,4,5 and 6 is 60.This means that 61,121,181 etc. gives remainder 1, when divided by 2,3,4,5 and 6.You have to check whether 61,121,181 etc are now multipled. Display and mention the number of iterations needed to generate in the first case and last case.
2, 3, 5, 11, 23, 29, 41, 53, 83, 89, 113, 131.......