0% found this document useful (0 votes)
7 views

All CPP and Java

Uploaded by

Arya Naik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

All CPP and Java

Uploaded by

Arya Naik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

EXPERIMENT NO-1

ADDITION OF TVWO NUMBERS

#include <iostream>

using namespace std;


int main()

int a,b,c;
cout << "Enter first number:":
cin >> a;

cout << "Enter second number:";


cin >> b;
C=a+b;
cout << "Sum of the twO numbers is: "'<< C;

return0;

-- OUTPUT

Enter first number: 10


Enter second number: 20

Sumof the two numbers is: 30


==Code Execution Successful ===

lence The program is been executed


Output :
main()
int <iostream>
namespace std;#include
using

return0; else else if


(a
cin
>>
cout float Experiment ProcesSS
Press 1 B 0 e
= = = =
if if >= << a, falsefalse
tue true
(c (b b a
cout >= cout >= cout >>"Enter b, any
&& c;
b exited 8&&&
<<c<<" &&c= a <<b a
&& <<a a >> key &&&&
>= c; three true
false
<< b <<" c) truefalse
" >= to
the
is b)
the
is c)
the
is
numbers: 2: after
continue
largest largest largest
Find
0.06664
":
number"; number"; number"; the
seconds
largest
with
among return

value
3
numbers
gjoh Output: mainint () <iostream>
namespace std:#include
using

return 0; for ci>>


nn; cout intn;
i,
Process13*10=130
Press 13*8=1044
13*9=11713*7=91
13*6=78 13*1=13Enter
13*3=39
13*5=65 13*2=26
13*<=52 (i=1;
<<
cout i<=10; "Enter
any
exited
a
<<n<<"* Experiment
key number: 13
i i++) number:": a

to
oftor
usinq
after.
continue
<<i<<"="

3.21
ee n
<<i*n
4:
seconds <<
Multiplication
endl;

with
return
loop Table
value

0
table he
Process
Press
keyany Enteredenter Press
rocess Enteredenter Output : inta;
return 0; else { cout else if(a cout<<"'
cin>>a; enter int{m#iainnàmespace
ncl()ude<iusionststd;g ream>
==
the
<< ifla
the any cout cout 0)
Number exited Number "Entered > { Experiment
exited
number: key number: «"Entered 0):{ <<"Entered
the
to to is Number number:
is after
after continue
continue Negative -101 Positive 100
Number Number
is
5.227 2.254.seconds Positive" ";
is is
3:
Negative" 0"
Sseconds << <<
Positive
endl; endl;
with with <<
endi;
return return and
value value
Negative
0

Numbers

2451
-
Press
ProcesS
exited Entered
number:18 Press.
any 6.67 enter.the ProcesS Enteredenter Output : cout
return0; }. cout else{ cin>>a, inta;
if(a%2==0){ cout<<"enter #imainnamespace
cln()inut de<iusiongststdr;eam>
<< <<
any the "Entered.Number "Entered
Number exited Numiber
key key number:
the
to to
Number
after is after is number:
continue Even continue Odd 69
is is Experiment
3.799 Odd" Even" ":
<< <<
seconds seconds endl; endi:

with with
3:
return retyrn Odd
value value and
e 0 Even
Output :
main() <iostream>
namespace
int using
std;#include
return 0; cout I/true cout I/true cout //false cout //false 10;b= 5; b;
a= inta,
<< && << << <<
(a && &&
(a (a (a &&
==true= > false < true
5) 0) < false
0) 0)
&&true && = && = && =
false false false
(b (b (b (b>
> < ==
0)) 0)) 15) Experiment
10))
<<"= <<"=
<<" <<"
true true = =
false false
&& &&
&& &&
true" false"
true" false" 2:
<«endl; << AND
endl; << <<
endl; endl;
Gate
Output: mainamespace
int ()usin<ig sto#idst;nrcleam>
ude
return 0; cin>>
a; cout cin>>
n; cout int Experiment
for i,
(=1; <<"Enter << n,
5*11=55
Process 5*12=6O
Press 5*10=50 5*8=40
5*9=45 5*735 5*44=20
5*6-305*5=25 5*2=105*1=5
5*3=15 EnterEnter a;
cout "Enter
iea;
any the a. t.e a 4:
e exited number: <<n<<"*"<<i<<"=" it+) number:
key number number Multiplication
to ":
after 5 of.
continue of
multiples:
no.
29.92 multiples:
«i*n
";
seconds <<
12 endl: Table
n
with

return !
with
be
value
user
the defined
. 0

table range
Experiment 5: Create an object of aclass andits attributes
tinclude <iostream>

#include <string>

using namespace std;

class student

public:

int Rollno;

string Name;

float Percentage;

int main()

student std;

std.Rollno = 27;

std.Name = "Rahul":

std.Percentage = 91;

cout << "Roll No: "<< std. Rollno <<"\n":

cout << "Name: " << std. Name <«"\n";

cout << "Percentage: " << std.Percentage << "\n";

return 0;

Output :
Roll No: 27
Name: Rahul
Percentage: 91

Process exited after 6.05714 Seconds with eturn valiue A


Press any key to continue
Output: main()int Percentage:"<<
Percentage; student:put
Details(void)
void
Press Name:
Process Student
DetailEnterEnterName:
Rahul
: Enter return O; cout cout
std.putDetails():
std.getDetais(}: studentstd;
any Rahul Marks Roll <<"Name:"<< "Student<<
exited
key number:
Roll out Detail
to
after of Name
continue number: :\n":
5O0: 27 <«"
19.78 Roll
369
27 number:
Seconds
Total: "
<<
with Rollno
369
<e"
return
Percentage: Total:
"
valve <<
Total
<<
73.8
student:get
Details(vold)
void student
class narmespace <iostream>
<string>
usingstd;#include#include

Rollno;dn
>> cOut Name;dn> cout
Experiment
(float)Total/500*100;
Percentage =Total;cdn>> CDut public:
<< << <<
"Enter "Enter "Enter putDetails(void):
vold Percentage;
getDetails(vold):
vold float Total;int Name[30|:
int char
Rollno;
Marks Roll Name: 6:
out
number:":
"; Create
of with
S00:";
user an
obiect
defined
of
inputs class a
and
its
attributes
clu
'-
Output : main()int student::putDetails(void)
Percentage:" << void
Process
Press Name:
Studernt number
Enter
DetailEnterRoll
Rahul
Enter
Name:
return 0;
std.getDetails();
std.putDetails(); studentstd; Cout cout

<< <<
ey Rahul Marks "Name:""Student
exited Percentage;
Key
Dut <<Detail
to Roll Name
after of
Continue \n": :
number: 586: 27 <<
19. "
Roll
78 369
number:
ttt 27
seconds
Total: "
<<
with Rolln0
369
return <<"
Percentage: Total:"

value <<
Total

& <<"
E 73.8
student::getDetails(void)
void student
class namespace <string>tinclude
usingstd;tinclude Experiment
Rollno;cin>> cout Name;cin>> cout
(float)Total/500*100;
Percentage =Total;cin>> cout public: <iostream>
<< << <<
"Enter "Enter "Enter putDetails(void);
void Percentage;
getDetails(void); Name[30];
int char
void float Total;int Rollno;

Marks Roll Name: 5:


number: Create
out ";
of
with
500:": ";
user an
object
defined
of
inputs class a

and
its
attributes
java.util.Scanner;
public import */ **
package
name2;
a public */
*@param ** @author
ET-231 Click *license Click *
b=a+b; input.close();
=ba =a input.nextint();
input.nextlnt();
b= a= Scanner inta,
b;
System.outSystem.out.
.printinSwappi
("Aftenrg: ") -
rint("Enter
System.- out.pSystem.out.print("Enter class
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-
a; b; static nbfs://nbhost/System
input Name2
void args
println("First Experiment
the {
new = main(String
command
Scanner(System.in);
number second first FileSystem/Templates/Classes/Main.java
l line
number: args){
=" number: arguments
ta+ 8:
"; Swapping
"\nSecond ");

number

="+
of
h):
two
default.txt
to
edit numbers
this
to
template change

this
} util.Scanner;
public import
java. @author
ET-231 * ** */ license
public * ** package
name2; Click * Click *
temp;
num2 =num2; =num1;
temp =
num1 input.close();num2input.nextInt();
num1 = Scanner int @param
Experiment
System.out.System.out.
println("After
Swapping: "; System.out.print("Enter
System. out.print("Enter num1, static class
= nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.
java txt
input. input args
Name2
num2, void
print("First
nextint(); the { numbers
(using 8:
new =main(String[]
temp
command Swapping
number Scanner(System.in); =
second first 0;
number: args) line
=" number:
+ { arguments
numl
"): of
+ ");
\nsecond two

number

="+
num2): to
edit
this
to
template change variable)
temp
this
java.util.Scanner;
public import */ **
package
name2; *Click license Click *
public */
*@param ** @author
ET-231 Experiment
sum
System.out.print(sum); input.close(): num2 num1 Scanner int
System.out.print("Enter
System.out.print("Enter num1, class nbfs://nbhost/SystemFileSystem/Templates/Lice
nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java
= static
num1 = Name2
input. input. = input
num2, void args
+
num2; nextInt(); extlnt(); = the {
new main(Stringl]
sum; command
Scanner(System.in); 7:
second first
number: args) line Addition
number:
{ arguments
");
"):
of
two
nses/license-default.txt
number

to
edit
with
this
to
template change user
this
input
** */
Output: public @author
ET-231 * package
name2; *license Click *
public */ * ** Click
Sum 61;b= 20; a= int @param
System.out.print(sum); a, nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java
class nbfs://nbhost/SystemFileSystem/Templates/Lice
= b,static
a Name2
+ sum;
b; void args
the
Experiment
main(String) {
command
81BUILD run:

args) line
SUCCESSFUL arguments
{ 7:
Addition
(total

tine: nses/license-default.txt
0
of
seconds) two
to
edit numbers
this
to
template change

this
Output: com.mycompany.exp10:
java.util.Arrays;
Exp10(
publclaicss import package
public
int
System.out.println(Arrays.toStringlage)); age[] static
=
{12,23,34,22,55,1,3,44}; void
[12, main(String[
Successful
Execution
Code
23,
array 34, Experiment
10a- B
22, args)
55, {
umbe ts
1,
3,
44]

-to
usioh -
Output : Com.mycompany.exp9;
java.util.Arrays;
public import package
public
System.out.printin("Sixth System.out.println("First
System.out.println("Acessing
System.out.println("Second
System.out.println("Fifth
System.out.printin("Fourth int
System.out.printin age[] static
class
SixthFifth
FourthThird First
SecondAcessing
= void Exp9
{12,34,22,55,44,3}; {
i rg element
element elementelement main(Stringl]
elementelement
the ("Third
(a n elements elementelement element element
in in element
in in in in element the args) Experiment
arayarrayarrayarrayarrayarray
in in in elements
in {
arrayarray:" in inarray
of array:" array
array:"+age[1]);
: : : :"+age[5); :" of
3 44 : 22 : 12 an :"
55 34 + + age[o]); + an
age[4]); age[2]);+ Array");
Array age[3]);: 9
|0
-A
Q1B. WRP TODISPLAY NUMBERS FROM 1TO 7USING DO-WHILE LOOP IN
JAVA.

PROGRAM:
package dowhileloop;
public class Dowhileloop {
public static void main(String[] args) {
int i=1,n=7;
do

System.out.printin(i);
i++;

while(i<=n);

OUTPUT:- 1
2

BUILD SUCCESSFUL (total time: 0 seconds)

orelugion- dowh le

UseA the
OUTPUT:: 1
public whileloop;
publicpackage
PROGRAM: 01A.
I/whileloop
it+;while(i<=n){
System.out.println(i); int
i=1,n=5; static class WRP
BUILD 5 4 3 2 Whileloop TO
void
from DISPLAY
SUCCESSFUL main(Stringl]
1 {
to NUMBERS
5
(total args){ EXPERIMENT 9
FROM
time:

0 1
seconds) TO
5
USING

WHILE
LOOP

IN
JAVA.
luSion: second
number
Enter
21 number
112Enter
first 243Enter number
first
secon 1001Enter Choose number
Enter
22 number
Enter
first +
division second
number
Enter
22 number
373Enter
first Choose Choose
SubtraCtion number Addition second Output:
10 Choose
altiplication
an break;
an an break; System.out.println("multiplication
System.out.println("division result case'/": result
operator an
of operator of
operator of operator
the = =
the the a/ a
of *
numbers the numbers : b; b;
: : numbers
t/or* t,-,
t,/or numbers :
usirg9 Sinple is /or* t,/ork
is
758.0 is
l6.954545454545453 is
32.0
2352.0 of
the
lealatot
ith ( numbers of
the
numbers
is
"+
result); is
"+result);

been
mae
java.util.Scanner:
com.mycompany.exp11;
public import package
input.nextDouble(); a= operator operator;
Scanner double char public
switch(operator){
System.onextDouble();
utSyst System.out.printin("Choose
.prinetm.Iinput.n("Ent
onumber
utb=.second
perirn")t:in("Ent
number
erf"ir)s:t class
break; break; result
=a+ case'+':
b; static
a, Exp11
em.outcase'*:
.printin("subtractiSyst
on eresultm.ocase'ut.p-ri': ntin("Addi tion = input b, void
=a input. result; {
- =
b; new
next(). main(Stringl]
Scanner(System.
charAt(0); in);
an args)
operator Experiment 11
of {
of the
the numbers :
+,
numbers -/or*");
is
is "
+
"+ result);
result):
reusioh Output : com.mycompany.exp10;
java.util.Arrays;
Exp10{
public
class import package
int public
System.out.printin(Arrays.deepToString(age)); age[][0 static
==
= void
L[12. {{12,23},(34,22,55),(1,3,44};
Code
main(Stringl]
23].
Execution Experiment
10b-C
to ee n
imeSiorg [34. args)
22, {
prit Successful 55].
[1,
by 3,
===
uts. u 44]]
atta
vowe isi
OUTPUT:
Concusion Code nublic CODE:
if
public
else { char
ch= 'i";
(ch class
Execution System.out.printin(ch
System.out.printin(ch == static
'a' VowelConsonant
|| void
Successful ch
==main(String[]
'e'
Vowel || Experiment )4-
+ + ch
alphabet === " " {
is is ==
consonant'"); vowel"); '" args)
||
(an ch {
==
'o'
||
checkel ch
==
'u')
CahSo
nant
{

Sr
Experiment -13

CODE:

Experiment13 {
Dublic class
public static void main(String[) args) {
int dividend=25,divisor=4:
int quotient=dividend / divisor:
int remainder=dividend % divisor:

System.out.printin("Quotient="+quotient);
System.out.println("Remainder="+remainder):

OUTPUT:
Quotient=6
Remainder=1

=== Code Execution Successful

Remain der ahd Quaent


(onclusion
Can displayed TAVA

Experment44
89
your marks:
Enter
your 30
== your marks:
Enter
your
Successful
Execution
Code
experiment12{
nubl
class
java.util.
Scanner:
ic import
pass Code fail
CODE:
input.close(); Scanner(System.in);
marks=input.nextDouble();
result=(marks>40)?"pass":"fail":
String Double
System.out.printin("Enterinput=new
marks:");
yourScanner publstaticvoiic d
System.out.println("your"+result+"
the Execution the
exam
exam.
.
Pass Successful main(String[]args){

===
Experiment12
-

verii ed the
exam.
");
accordirg

You might also like