[Go to site: main page, start]

0% found this document useful (0 votes)
13 views9 pages

Java Programs - 2

The document contains a series of Java code snippets that implement various algorithms for mathematical and string operations, including prime number checks, co-prime numbers, LCM, HCF, and palindrome checks. Each section of code is labeled with a specific task, such as finding unique numbers, Armstrong numbers, and Fibonacci series. The document is structured as a programming guide with examples and explanations for each algorithm.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

Java Programs - 2

The document contains a series of Java code snippets that implement various algorithms for mathematical and string operations, including prime number checks, co-prime numbers, LCM, HCF, and palindrome checks. Each section of code is labeled with a specific task, such as finding unique numbers, Armstrong numbers, and Fibonacci series. The document is structured as a programming guide with examples and explanations for each algorithm.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. PRIME NUMBER n=in.

nextInt(); SOPln ("The hcf="+hcf);


n=[Link](); for(i=1;i<=n;i++)
for(a=1;a<=n;a++) { [Link] NUMBER
{ if(n%i==0) n=[Link]();
if(n%a==0) c=c+1; no=n;
c=c+1; } for(int i=0;i<=9;i++)
} if(c==2) {
if(c==2) { n=no;
SOPln(“Prime no.”); do c=0;
else { while(n>0)
SOPln(“Not a Prime no.); r=n%10; {
} s=s*10+r; int d=n%10;
n=n/10; if(d==i)
[Link]-PRIME NUMBERS }while(n!=0); c++;
a=[Link](); } n=n/10;
b=[Link](); int g,h=0; }
p=a*b; for(g=1;g<=s;g++) if(c>1)
for(i=1;i<p;i++) { flag=0;
{ if(s%g==0) }
if(a%i==0 && b%i==0) h=h+1;} if(flag==1)
{ if(h==2) SOPln ("unique number");
hcf=i; SOPln ("twisted prime else
}} number"); SOPln ("not a unique
if(hcf==1) else number");
SOPln("coprime numbers SOPln ("not a twisted prime
"+hcf); no"); [Link] HIGHEST OR
else } SMALLEST NUMBER
SOPln ("not coprime [Link] public static void main(int
nos"+hcf); a=[Link](); a,int b,int c)
b=[Link](); {
[Link] PRIME NUMBERS int pro=a*b; int max,min,sec;
a=[Link](); p=[Link](a,b); max=[Link]([Link](a,
b=[Link](); for(i=p;i>=1;i--) b),c);
for(i=1;i<=a;i++) { min=[Link]([Link](a,b)
{ if(a%i==0 && b%i==0) ,c);
if(a%i==0) { sec=(a+b+c)-(max+min);
c=c+1; gcd=i; SOPln(sec);
} break; }}
for(g=1;g<=b;g++) }}
{ lcm=pro/gcd; 9. BUZZ NUMBER
if(b%g==0) SOPln ("The lcm="+lcm); int t=[Link]();
d=d+1; if(t%7==0||t%10==7)
} 6. HCF SOPln(t +" Buzz Number");
if(c==2 && d==2) a=[Link](); else
{ b=[Link](); SOPln(t +" not a Buzz
if((a-b==2) || (b-a==2)) p=[Link](a,b); Number ");
SOPln ("twin prime for(i=p;i>=1;i--) 10. TO FIND FACTORS
numbers"); { int t=[Link]();
else if(a%i==0 && b%i==0) int i;
SOPln ("not twin prime nos"); { for (i=1;i<t;i++)
} hcf=i; {
4. TWISTED PRIME break; if(t%i==0)
NUMBERS }} [Link](i +" "); }
1
11. EQUABLE TRIANGLE } 18. AUTOMORPHIC
a=[Link](); if(r==p) NUMBER
b=[Link](); SOPln("palindrome number n=[Link]();
c=[Link](); "+n); s=n*n;
p=a+b+c; else y=0;
s=p/2; SOPln ("not palindrome while(n!=0)
ar=[Link](s*(s-a)*(s-b)*(s- no"+n); {
c)); if(n%10!=s%10)
if(p==ar) 15. NEON NUMBER {
SOPln("equable triangle"); n=[Link](); y=1;
else p=n*n; }
SOPln("not a equable while(n!=0) n=n/10;
triangle"); { s=s/10;
} d=p%10; }
s=s+d; if(y==0)
[Link] of successor of p=p/10; SOPln(“automorphic no”);
even digits eg:2745 even } else
digit=2,4 = 3*5=15 if(s==n) SOPln(“not automorphic no”);
a=[Link](); SOPln("neon number "+n);
while(a!=0) else [Link] NUMBER
{ SOPln ("not neon no"+n); n=[Link]();
r=a%10; p=n;
if(r%2==0) 16. ARMSTRONG NUMBER while(n!=0)
{ n=[Link](); {
r=r+1; num=n; d=n%10;
b=b*r; while(n>0) sum=sum+d;
} { n=n/10;
a=a/10; d=n%10; }
} s=s+(d*d*d); if(p%sum==0)
SOPln("the product="+b); n=n/10; SOPln(“niven number”);
} else
13. PERFECT NUMBER if(num==s) SOPln(“not a niven number”);
n=[Link](); SOPln("armstrong number
for(i=1;i<n;i++) "+num); [Link] SERIES
{ else int a=0,b=1,c=0,i;
if(n%i==0) SOPln ("not armstrong SOP(a+”,”+b);
{ no"+num); for(i=3;i<=10;i++)
s=s+a; {
} 17. DUCK NUMBER c=a+b;
if(s==n) n=[Link](); SOP(”,”+c);
SOPln("perfect number "+n); num=n; a=b;
else while(n>0) b=c;
SOPln("not perfect { }
number"+n); r=n%10; [Link] SERIES
if(r==0) int a=0,b=1,c=2,d=0,i;
14. PALINDROME NUMBER c++; SOP(a+”,”+b+”,”+c);
n=[Link](); n=n/10; for(i=4;i<10;i++)
p=n; } {
while(n!=0) if(c>=1) d=a+b+c;
{ SOPln("duck number"); SOP(”,”+d);
d=n%10; else a=b;
r=r*10+d; SOPln ("not duck number"); b=c;
n=n/10; c=d; }
2
[Link] NUMBER if(h==3) if(s==p)
a=[Link](); SOPln("circular prime no"); SOPln("sumproduct no.");
sum=a; else else
do SOPln("not a circular prime SOPln("not a sumproduct
{ number"); no.");
a=sum;
sum=0; 24. Multiple harshad no. 26. DISARIUM NUMBER: if
do Sample input:6804 the sum of the digits
{ 6+8+0+4=18,6804/18=378 powered with their
d=a%10; 3+7+8=18,378/18=21 respective position is
sum=sum+d*d; 2+1=3,21/3=7 equal to original no.
a=a/10; int n,n1,r=0,har=0,s=0; Sample Input = 518 =
}while(a>0); SOPln("Enter a number"); 51+12+83 = 518
}while(sum>9); n=[Link]();
if(sum==1) n1=n; int n,len=0,d=0,sum=0,n1;
SOPln("happy number"); do String s;
else { Sopln("enter a number");
SOPln("not a happy n=n1; n=[Link]();
number"); s=0; n1=n;
while(n!=0) s=[Link](n);
{ len=[Link]();
23. CIRCULAR PRIME r=n%10; while(n1>0)
Sample input:197 s=s+r; {
[shift first digit to last and n=n/10; d=n1%10;
check for prime 197,971, } sum=sum+(int)Math.
719 all should be prime no] if(n1%s==0) pow(d,len);
int n,i,f,h=0,q=0,g=0; har++; len--;
String s="",t=""; n1=n1/s; n1=n1/10;
SOPln("enter a number"); }while(n1>10); }
n=[Link](); if(har>=3) if(sum==n)
g=n; SOPln("multiple harshad Sopln("disarium number");
do no."); else
{ else Sopln("not disarium
f=0;s=""; SOPln("It is not a harshad number");
for(i=1;i<=n;i++) no.");
{ 27. Accept a number and
if(n%i==0) 25. SUMPRODUCT NUMBER display smallest digit in it
f++; Sample input: 123
} 1+2+3=1*2*3 int n,r,min;
if(f==2) SOPln("enter a number");
{ int n,s=0,p=1,r=0; n=[Link]();
h++; SOPln("enter a number"); min=n%10;
t=[Link](n); n=[Link](); while(n!=0)
s=s+[Link](1)+[Link](2)+t. while(n!=0) {
charAt(0); { r=n%10;
q=[Link](s); r=n%10; if(r<min)
n=q; s=s+r; min=r;
} p=p*r; n=n/10;
else n=n/10; }
SOPln("not prime no."); }
}while(n!=g); SOPln("The smallest digit in
a number is “ + min);

3
1. TO CHECK PALINDROME t=[Link](p,i); [Link] OF
WORD if([Link]()>m) ALPHABET IN SENTENCE
st=[Link](); { int a=0,r,b;
p=[Link](); max=t; String st;
for(i=p-1;i>=0;i++) m=[Link](); char chr,chr1;
{ } SOPln("enter a String in
chr=[Link](i); p=i+1; uppercase");
st1=st1+chr; }} st=[Link]();
} SOPln("Longest word" +max);SOPln("enter a alphabet's
If([Link](st1)) SOPln("Longest word length"freq to be checked");
SOPln(“Palindrome”); +m); chr1=[Link]().charAt(0);
else b=[Link]();
SOPln(“Not Palindrome”); [Link] OF CONSONENTS for(r=0;r<b;r++)
IN SENTENCE {
2. PALINDROME WORDS IN int a,b=0, v=0; chr=[Link](r);
A SENTENCE st=[Link](); if(chr==chr1)
String wd,t,wd1=""; st=[Link](); a++;
char chr; b=[Link](); else
int i,j,l=0,p=0; for(a=0;a<b;a++) continue;
SOPln("Enter a string"); { }
wd=[Link](); chr=[Link](a); SOPln("Frequency of " +chr1
wd=[Link](); if(chr=='A'||chr=='E'||chr==' +"is" +a);
l=[Link](); I'||chr=='O'||chr=='U'||chr=
wd=wd+" "; =' ') [Link] OF EACH
for(i=0;i<=l;i++) continue; LETTER IN SENTENCE
{ else int i,l=0;
if([Link](i)==' ') v=v+1; SOPln("enter a string");
{ } st=[Link]();
t=[Link](p,i); SOPln("No. of alphatbets st=[Link]();
int l1=[Link](); excluding vowels" +v); int arr[]=new int[26];
for(j=l1-1;j>=0;j--) for(i=0;i<26;i++)
{ [Link] OF VOWELS IN {
chr=[Link](j); SENTENCE arr[i]=0;
wd1=wd1+chr; int a,b,v=0; }
} String st; l=[Link]();
if([Link](wd1)) char chr; for(i=0;i<l;i++)
SOPln("palindrom word ="+ [Link]("enter a {
wd1); String"); if([Link](i)>=65 &&
wd1=""; st=[Link](); [Link](i)<=90)
p=i+1; st=[Link](); {
} } b=[Link](); arr[[Link](i)-65]++;
for(a=0;a<b;a++) }}
[Link] WORD IN { SOPln("CHARACTER \t
SENTENCE chr=[Link](a); FREQUENCY");
int p=0,m=0; if(chr=='A'||chr=='E'||chr==' for(i=0;i<26;i++)
s=[Link](); I'||chr=='O'||chr=='U') {
s=[Link](); v=v+1; if(arr[i]!=0)
int x=[Link](); else {
s=s+ " "; continue; SOPln((char)(i+65) + "\t\t\t"
for(int i=0;i<=x;i++) } + arr[i]);
{ [Link]("No. of } }
if([Link](i)==' ') vowels" +v);
{
4
[Link] OF DOUBLE 10. UNIQUE WORD SOPln("enter a sentence");
LETTER SEQUENCES String st; s=[Link]();
String st; SOPln("enter a string"); l=[Link]();
char x,y; st=[Link](); s=" "+s;
int i,l=0,c=0; char ch,y; s=[Link]();
SOPln("enter a string");int i,l=0,j=0; for(i=0;i<l;i++)
st=[Link](); l=[Link](); {
l=[Link](); st=[Link](); ch=[Link](i);
st=[Link](); for(i=0;i<l-2;i++) if(ch==' ')
for(i=0;i<=l-2;i++) { SOP([Link](i+1));
{ ch=[Link](i); }
x=[Link](i); y=[Link](i+1);
y=[Link](i+1); if(ch==y) 13. DISPLAY SURNAME
if(x==y) j++; FIRST FOLLOWED BY
c+=1; else FIRST & SECOND NAME
} continue;
[Link](c); } String s,fname="",mname="",
}} if(j>0) lname="";
SOPln("not a unique word"); int fn=0,mn=0,ln=0;
[Link] OF VOWELS else SOPln("enter a name with
IN A SENTENCE SOPln("it is a unique word"); three words");
s=[Link]();
int a=0,e=0,i=0,o=0,u=0,r,b; 11. REPLACE ONLY s=s+" ";
String st; VOWELS WITH NEXT fn=[Link](' ');
char chr; ALPHABET IN A WORD fname=[Link](0,fn);
SOPln("enter a String in int i,b; mn=[Link](' ',(fn+1));
uppercase"); String st,s=""; mname=[Link](fn,mn);
st=[Link](); char chr; ln=[Link](' ',(mn+1));
b=[Link](); SOPln("enter a String"); lname=[Link](mn,ln);
for(r=0;r<b;r++) st=[Link]().toUpperCase(); SOP(lname + fname +
{ b=[Link](); mname);
chr=[Link](r); for(i=0;i<b;i++)
if(chr=='A') { 14. DISPLAY NO. OF
a++; chr=[Link](i); LOWERCASE & UPPER
else if(chr=='E') if(chr=='A') CASE ALPHATEBET IN A
e++; [Link](s+'B'); SENTENCE
else if(chr=='I') else if(chr=='E') int i,p,lc=0,uc=0;
i++; [Link](s+'F'); char ch; String st;
else if(chr=='O') else if(chr=='I') SOPln(“Enter a sentence”);
o++; [Link](s+'J'); st=[Link]();
else if(chr=='U') else if(chr=='O') p=[Link]();
u++; [Link](s+'P'); for(i=o;i<p;i++)
else else if(chr=='U') {
continue; [Link](s+'V'); ch=[Link](i);
} else if(ch>=’a’&&ch<=’z’)
SOPln("Freq. of 'A' =" +a); [Link](s+chr); lc=lc+1;
SOPln("Freq. of 'E' =" +e); } if(ch>=’A’&&ch<=’A’)
SOPln("Freq. of 'I' =" +i); uc=uc+1;
SOPln("Freq. of 'O' =" +o); 12. DISPLAY ONLY FIRST }
SOPln("Freq. of 'U' =" +u); LETTER IN A SENTENCE SOPln(“Uppercase =”+uc);
SOPln(“Lowercase =”lc);
String s;char ch;
int i,l;
5
[Link] 3 letter word and g=sum; OVERLOAD FUNCTION
print all the probable three- sum=0; Page 314 QNo - 18
letter combinations do
Sample input: TOP { public class overload
Sample output:TOP,TPO, d=g%10; {
OPT,OTP,PTO,POT sum=sum+d*d; void calculate(int m,char ch)
String str; g=g/10; {
int i,j,k,p; }while(g>0); if(ch=='s')
SOPln(“Enter 3 letter word”); }while(sum>9); {
str=[Link](); if(sum==1) if(m%7==0)
p=[Link](); SOPln("happy word"); Sopln("divisible by 7");
for(i=0;i<p;i++) else else
{ SOPln("not a happy word"); Sopln("not divisible by 7");
for(j=0;j<p;j++) }
{ 17. Accept non-palindrome else
for(k=0;k<p;k++) word and make it {
{ palindrome if(m%10==7)
if(i!=j&&j!=k&&k!=i) Sample input: ICSE Sopln("the last digit is 7");
SOP([Link](i)+” “ Sample Output: ICSEESCI else
+[Link](j)+” String wd,wd1="",palin=""; Sopln("last digit is not 7");
“+[Link](k)); char chr; }}
} int i,l=0; void calculate(int a, int b,
SOPln(); SOPln("Enter a word"); char ch)
} wd=[Link](); {
} l=[Link](); if(ch=='g')
for(i=l-1;i>=0;i--) {
16. HAPPY WORD { int c=[Link](a,b);
Sample input: VAT chr=[Link](i); Sopln("greatest [Link]="+c);
[Hint A=1,B=2......z=26 wd1=wd1+chr; }
VAT=22120 } else
22+22+12+22+02=13 palin=wd+wd1; {
12+32=10 SOPln(palin + "It is a int c=[Link](a,b);
12+02=1] palindrome word"); Sopln("smaller no is ="+c);
Sample output:Happy Word }}}
18. Accept a string and Page 315 QNo - 27
String a; print it in alphabetical public class overload
int l,i,sum=0,d=0,b,g=0; order {
char ch; String str; double V=0.0;
SOPln("enter a String"); int i,j,p; double volume(double r)
a=[Link]().toUpperCase(); char ch; {
l=[Link](); SOPln("enter a String"); V=4.0/3.0*3.14*r*r*r;
for(i=0;i<l;i++) Str=[Link](); return(V);
{ p=[Link](); }
ch=[Link](i); for(i=65;i<=90;i++) double volume(double h,
b=(int)ch-64; { double r) {
if(b<10) for(j=0;j<p;j++) V=3.14*r*r*h;
g=g*10+b; { return(V);
if(b>=10) ch=[Link](j); }
g=g*100+b; if(ch==(char)i||ch==(char)(i+ double volume(double l,
} 32)) double b, double h)
sum=g; [Link](ch); {
do }} V=l*b*h;;
{ return(V); } }
6
NUMBER PATTERNS a) 1 b)15 a) p=1; b) p=15;
a)1 b)1 23 14 13 for(r=5;r>=1;r--)
12 22 456 12 1110 {
123 333 7 8 910 9 8 7 6 for(c=1;c<=r;c++)
1234 4444 1112131415 5 4 3 21 {
12345 55555 a) p=1; b) p=15; a) SOP(p+” “);
for(r=1;r<=5;r++) for(r=1;r<=5;r++) p++;
{ { b) SOP(p+” “);
for(c=1;c<=r;c++) for(c=1;c<=r;c++) p--;
{ { }
a) SOP(c+” “); a) SOP(p+” “); SOPln();
b) SOP(r+” “); p++; }
} b) SOP(p+” “);
SOPln(); p--; a)12345 b)55555
} } 1234 4444
SOPln(); 123 333
a)5 b)5 } 12 22
54 44 1 1
543 333 a) 12345 b) 55555 for(i=5;i>=1;i--)
5434 2222 1234 4444 {
54321 11111 123 333 for(j=5;j>i;j--)
for(r=5;r>=1;r--) 12 22 {
{ 1 1 SOP(“ “);
for(c=5;c>=r;c--) }
{ for(r=5;r>=1;r--) for(k=1;k<=i;k++)
a) SOP(c+” “); { {
b) SOP(r+” “); for(c=1;c<=r;c++) a)SOP(k);
} { b)SOP(i);
SOPln(); a) SOP(c+” “); }
} b) SOP(r+” “); SOPln();
} }
a)1 b)* SOPln(); }
10 *# }
101 *#* a) 54321 b) 11111 a) 5 b) 5
1010 *#*# 5432 2222 54 44
10101 *#*#* 543 333 543 333
for(r=1;r<=5;r++) 54 44 5432 2222
{ 5 5 54321 11111
for(c=1;c<=r;c++) for(r=1;r<=5;r++) for(i=5;i>=1;i--)
{ { {
if(c%2==0) for(c=5;c>=r;c--) for(j=1;j<i;j++)
a) SOP(“0”+” “); { {
else a) SOP(c+” “); SOP(“ “);
SOP(“1”+” “); b) SOP(r+” “); }
b) SOP(“#”+” “); } for(k=5;k>=i;k--)
else SOPln(); {
SOP(“*”+” “); } a)SOP(k);
} b)SOP(i);
SOPln(); a) 1 2 3 4 5 b)1514131211 }
} 6 789 10 9 8 7 SOPln();
101112 6 54 }
1314 3 2 }
15 1
7
STRING PATTERNS
a) BLUEJ b) JJJJJ
a)B b) B a)A b)O BLUE EEEE
BL LL BC NM BLU UUU
BLU UUU DEF LKJ BL LL
BLUE EEEE GHIJ IHGF B B
BLUEJ JJJJJ KLMNO ECDBA String s=”BLUEJ”;
String s=”BLUEJ”; a) p=65 b) p=79 int k=0;
int L=[Link](); for(r=1;r<=5;r++) L=[Link]();
for(int r=0;r<L;r++) { for(r=L-1;r>=0;r--)
{ for(c=1;c<=r;c++) {
for(int c=0;c<=r;c++) { for(c=r;c<L-1;c++)
{ a) SOP(p); p++; {
a)SOP([Link](c)); b) SOP(p); p--; SOP(" ");
b)SOP([Link](r)); } }
} SOPln(); for(k=0;k<=r;k++)
SOPln(); } {
} a)SOP([Link](k));
b)SOP([Link](r);
a)J b) J a) BLUEJ b) BBBBB }
JE EE LUEJ LLLL SOPln();
JEU UUU UEJ UUU }
JEUL LLLL EJ EE
JEULB BBBBB J J
String s=”BLUEJ”; String s=”BLUEJ”; a) J b) J
int L =[Link](); int L =[Link](); JE EE
for(int r=L-1;r>=0;r--) for(int r=0;r<L;r++) JEU UUU
{ { JEUL LLLL
for(int c=L-1;c>=r;c--) for(int c=r;c<=(L-1);c++) JEULB BBBBB
{ { String s=”BLUEJ”;
a)SOP([Link](c)); a)SOP([Link](c)); int k=0;
b)SOP([Link](r)); b)SOP([Link](r)); L=[Link]();
} } for(r=L-1;r>=0;r--)
SOPln(); SOPln(); {
} } for (c=0;c<r;c++)
{
BLUEJ a) BLUEJ b) JJJJJ SOP(" ");
BLUEB BLUE EEEE }
BLUBL BLU UUU for(k=L-1;k>=r;k++)
BLBLU BL LL {
BBLUE B B a)SOPln([Link](k));
String s="BLUEJ"; String s=”BLUEJ”; b)SOPln([Link](r));
int i,j,l,k=0; int L =[Link](); }
l=[Link](); for(int r=L-1;r>=0;r--) SOPln();
j=l; { }
for(i=0;i<l;i++) for(int c=0;c<=r;c++)
{ {
SOP([Link](0,j)); a)SOP([Link](c));
SOP([Link](0,i)); b)SOP([Link](r));
j--; }
[Link](); SOPln();
} }

8
PRINT SUM OF THESERIES (7)a + a2/2 + a3/3 + ...... + a10/10 PRINT UPTO TEN SERIES
(1) 1 + 4 + 9 + ...... + 400 (1) 1, 4, 9, 16,……
int sum = 0; int a = [Link](); for (int i = 1; i <= 10; i++)
for (int i = 1; i <= 20; i++) double s = 0.0; SOP(i * i + " ");
sum=sum+ (i*i); for (int i = 1; i <= 10; i++)
SOPLN("Sum = " + sum); s=s+[Link](a, i)/i; (2) 1, 2, 4, 7, 11,……
SOPLN("Sum = " + s); int a=1,s=1;
(2)1 + (1/2) + (1/3) + ...... + (1/20) for (int i = 1; i <= 10; i++)
double sum = 0.0; {
for (int i = 1; i <= 20; i++) (8) (a*2) + (a*3) + ...... + (a*20) SOP( s + " ");
sum =sum+ (1.0 / i); s=i+a;
SOPLN("Sum = " + sum); int a = [Link]();
a++; )
long sum = 0;
(3) (1/2) + (2/3) + ...... + (19/20) for (int i =2; i <= 20; i++)
(3) 3, 6, 9, 12,……
double sum = 0.0; sum=sum+(a*i);
for (int i = 1; i <= 30; i+=3)
for (int i = 1; i <= 19; i++) SOPLN("Sum = " + sum);
SOP(i * i + " ");
sum =sum+ (double)(i / i+1);
(9) a + a2 + a3 + ...... + an
SOPLN("Sum = " + sum); (4) 4, 8, 16, 23,……
int a = [Link]();
for (int i = 2; i <= 11; i++)
(4) 2 - 4 + 6 - 8 + ...... – 20 int n = [Link]();
SOP((int)([Link](2, i))+ " ");
double sum = 0.0; long sum = 0;
for (int i = 1; i <= 10; i++) for (int i = 1; i <= n; i++)
(5) 1.5, 3.0, 4.5, 6.5,……
{ sum=sum+[Link](a, i);
float t=1.5;
if (i % 2 == 0) SOPLN("Sum = " + sum);
for(int i = 1; i <= 10; i++)
sum=sum-(i * 2); SOP(t * i + " ");
else (10) 1 + 22/a + 33/a2+ ....to n terms
sum=sum+(i * 2); int a = [Link]();
(6) 0, 7, 26, 63,……
} int n = [Link]();
for (int i = 1; i <= 10; i++)
SOPLN("Sum = " + sum); double sum = 1.0;
SOP(i*i*i) - 1 + " ");
for (int i = 2; i <= n; i++)
(5) (1*2) + (2*3) + ...... + (19*20) sum =sum+ [Link](i, i)
(7) 1, 9, 28, 65,……
int sum = 0; / [Link](a, i - 1);
for (int i = 1; i <= 10; i++)
for (int i = 1; i <= 19; i++) SOPLN("Sum = " + sum);
SOP(i*i*i) + 1 + " ");
sum =sum + i * (i + 1);
SOPLN("Sum = " + sum); (11) 1/a + 1/a2 + 1/a3 + ...... + 1/an
(8) 0, 3, 8, 15,……
int a = [Link]();
for (int i = 1; i <= 10; i++)
(6)a2 + a2/2 + a2/3 + ...... + a2/10 int n = [Link]();
SOP(i*i) - 1 + " ");
double sum = 0.0;
int a = [Link](); for (int i = 1; i <= n; i++)
(9) 2, 5, 10, 17,……
double s = 0.0; sum=sum+1/[Link](a, i);
for (int i = 1; i <= 10; i++)
for (int i = 1; i <= 10; i++) SOPLN ("Sum = " + sum);
SOP(i*i) + 1 + " ");
s=s+[Link](a, 2)/i;
SOPLN("Sum = " + s); (10) 4, 16, 36, 64,……
for (int i = 2; i <= 20; i+=2)
SOP(i*i) - 1 + " ");

You might also like