SlideShare une entreprise Scribd logo
1  sur  12
Some Examples And Things To Remember
C++ And Java
Programe to interchange the
values of two variables
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,num1,replace;

 cout<<"entre number 1"<<endl;
 cin>>num;
 cout<<"entre number 2"<<endl;
 cin>>num1;
 replace=num;
 num=num1;
 num1=replace;
 cout<<"after replacing
"<<endl<<num<<endl;
 cout<<"after replacing "<<endl<<num1;
 }
 public static void main(String[] args) {
 int num,num1,replace;
 Scanner a=new Scanner(System.in);
 System.out.println("entre number 1");
 num=a.nextInt();
 System.out.println("entre number 2");
 num1=a.nextInt();
 replace=num;
 num=num1;
 num1=replace;
 System.out.println("after replacing
"+num);
 System.out.println("after replacing
"+num1);



 }

Programe to find absolute of a
negative number(Without if else)
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,num1,replace;

 cout<<"entre negative number
"<<endl;
 cin>>num;
 int abs=num*-1;

 cout<<"abs value is
"<<endl<<abs<<endl;

 }
 public static void main(String[] args) {
 int num;
 Scanner a=new
Scanner(System.in);
 System.out.println("entre
negative number");
 num=a.nextInt();
 int abs=num*-1;
 System.out.println("absolute
value is "+abs);




 }
User entered 3 digit number break
it in single digits and display
accordingly
In c++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,bre,bre1,bre2,b,c;

 cout<<"entre 3 digit number "<<endl;
 cin>>num;
 bre=num/100;
 c=num/10;
 bre1=c%10;
 bre2=num%10;

 cout<<"first digit is "<<endl<<bre<<endl;
 cout<<"Second digit is "<<endl<<bre1<<endl;
 cout<<"third digit is "<<endl<<bre2<<endl;

 }
 public static void main(String[] args) {
 // TODO code application logic here
 int number,bre,bre1,bre2,b,c;
 Scanner a =new Scanner(System.in);
 System.out.println("entre 3 digit
number");
 number=a.nextInt();
 bre=number/100;
 c=number/10;
 bre1=c%10;
 bre2=number%10;
 System.out.println("first digit is "+bre);
 System.out.println("second digit is
"+bre1);
 System.out.println("third digit is
"+bre2);

 }
Difference between / and %
Division / Modulus %
 4/2 will give 2
 10/5 will give 2
 15/3 will give 3
 21/2 will give 10
 4%2 will give 0
 10%2 will give 0
 15/3 will give 0
 21/2 will give 5
 Help full tool used to break
the number in single digits
Marks entered by user find average
of these marks
In c++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int num,num1,num2;

 cout<<"entre marks of sub1 "<<endl;
 cin>>num;
 cout<<"entre marks of sub2 "<<endl;
 cin>>num1;
 cout<<"entre marks of sub3 "<<endl;
 cin>>num2;
 int avg=(num+num1+num2)/3;

 cout<<"avg is "<<endl<<avg<<endl;


 }
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 int number,number1,number2;
 Scanner a =new Scanner(System.in);
 System.out.println("entre marks of sub 1");
 number=a.nextInt();
 System.out.println("entre marks of sub 2");
 number1=a.nextInt();
 System.out.println("entre marks of sub 3");
 number2=a.nextInt();
 int avg=(number+number1+number2)/3;

 System.out.println("avarage is "+avg);

 }

 }
Temperature in fahrenheit is input
convert it into celsius
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 float far,cel;

 cout<<"entre temperature in farenhet
"<<endl;
 cin>>far;

 cel=(far-32)*5/9;

 cout<<"temp in celseius is
"<<endl<<cel<<endl;


 }
 */
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 double far,cel;
 Scanner a =new Scanner(System.in);
 System.out.println("entre temparature in
farenheit ");
 far=a.nextDouble();
 cel=(far-32)*5/9;
 System.out.println("Temp in cel is "+cel+"degree
celcius");

 }

 }
Ayaz basic salary is input through the keyboard. His dearness
allowance is 40% of basic salary, and house rent allowance is 20%
of basic salary. Write a program to calculate his gross salary.
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 float bsal,da,hr,gsal;

 cout<<"entre basic salary "<<endl;
 cin>>bsal;
 da=0.4*bsal;
 hr=0.2*bsal;
 gsal=bsal-da-hr;
 cout<<"Gross salar is
"<<endl<<gsal<<endl;


 }
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 double bsal,da,hr,gsal;
 Scanner a =new Scanner(System.in);
 System.out.println("Ayaz entre your basic
salary ");
 bsal=a.nextInt();
 da=0.4*bsal;
 hr=0.2*bsal;
 gsal=bsal-da-hr;
 System.out.println("gross salary is"+gsal);

 }

 }
If a three-digit number is input through the keyboard, write a program to print
a new number by adding one to each of its digits. For example if the number
that is input is 123 then the output should be displayed as 234.
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 int number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;
 cout<<"entre number"<<endl;
 cin>>number;
 bre=number/100;
 nbre=bre+1;
 c=number/10;
 bre1=c%10;
 nbre1=bre1+1;
 bre2=number%10;
 nbre2=bre2+1;
 cout<<"after adding 1 is"<<endl;
 cout<<nbre;
 cout<<nbre1;
 cout<<nbre2;

 }
 int
number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;
 Scanner a =new Scanner(System.in);
 number=a.nextInt();
 bre=number/100;
 nbre=bre+1;
 c=number/10;
 bre1=c%10;
 nbre1=bre1+1;
 bre2=number%10;
 nbre2=bre2+1;
 System.out.println("after adding 1 is");
 System.out.print(nbre);
 System.out.print(nbre1);
 System.out.print(nbre2);
Radius is input from user find area
In C++ In Java
 #include<iostream>
 using namespace std;
 int main()
 {
 float radius,area;
 cout<<"entre radius"<<endl;
 cin>>radius;
 area=3.14*radius*radius;
 cout<<"radius is"<<endl;
 cout<<area;


 }
 public class JavaApplication10 {
 /**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
 // TODO code application logic here
 double radius,area;
 Scanner a =new Scanner(System.in);
 System.out.println("entre radius");
 radius=a.nextDouble();
 area=3.14*radius*radius;
 System.out.println("area is"+area);


 }

 }
Key points
In C++ In Java
 In order to give one line gap we
use endl
 In C++ endl will give the one
line gap and cursor will go to
next line
 cout<<"entre radius"<<endl;
 In above instruction entre ra
dius will print and <<endl will
provide the one line gap
 Join string with variable we use
string << variablename;
 In order to give one line gap
we use System.out.println
 Here ln will give one line
break if we use
System.out.print it do not
give one line break and print
in the same line
 If we want to join string with
variable value we use + sign
Thanks alot
Contact me at
muhammadhaseeb562@gmai
l.com
Mobile no:-
0336-5686312

Contenu connexe

Tendances

Tendances (20)

Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
Python
PythonPython
Python
 
c programming
c programmingc programming
c programming
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
C++11
C++11C++11
C++11
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
Ee 3122 numerical methods and statistics sessional credit
Ee 3122 numerical methods and statistics sessional  creditEe 3122 numerical methods and statistics sessional  credit
Ee 3122 numerical methods and statistics sessional credit
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
functions
functionsfunctions
functions
 

En vedette

Understanding Mobile Consumer - Singapore
Understanding Mobile Consumer - SingaporeUnderstanding Mobile Consumer - Singapore
Understanding Mobile Consumer - SingaporeVijay Chander
 
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21  Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21 Robert Terry
 
Educacion comunicativa eric r
Educacion comunicativa eric rEducacion comunicativa eric r
Educacion comunicativa eric rAlbin Bas
 
1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs final1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs finalbvcsal
 
Conflict in Sri Lanka
Conflict in Sri LankaConflict in Sri Lanka
Conflict in Sri LankaAishaAziz
 
Are You Low On Magnesium?
Are You Low On Magnesium?Are You Low On Magnesium?
Are You Low On Magnesium?Katie Wells
 
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...ehsan sepahi
 
Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1Mary Bogen
 
A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...remyabalan78
 
Apuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoriaApuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoriasergio.historia
 
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2Weng Lun Ho
 
Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750S Sandoval
 

En vedette (20)

SU-030 Enrolling Users
SU-030 Enrolling UsersSU-030 Enrolling Users
SU-030 Enrolling Users
 
Study Review
Study ReviewStudy Review
Study Review
 
As
AsAs
As
 
Understanding Mobile Consumer - Singapore
Understanding Mobile Consumer - SingaporeUnderstanding Mobile Consumer - Singapore
Understanding Mobile Consumer - Singapore
 
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21  Civic Service, A Tale of 3 Paradigms, w notes    2015 Sept 21
Civic Service, A Tale of 3 Paradigms, w notes 2015 Sept 21
 
Membuat otline
Membuat otlineMembuat otline
Membuat otline
 
Educacion comunicativa eric r
Educacion comunicativa eric rEducacion comunicativa eric r
Educacion comunicativa eric r
 
The laundry railway
The  laundry railwayThe  laundry railway
The laundry railway
 
1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs final1ª corrida da proteção civil bvcs final
1ª corrida da proteção civil bvcs final
 
Conflict in Sri Lanka
Conflict in Sri LankaConflict in Sri Lanka
Conflict in Sri Lanka
 
Resume CA Avisha Vohra
Resume CA Avisha VohraResume CA Avisha Vohra
Resume CA Avisha Vohra
 
Métricas de Similaridade de Imagens
Métricas de Similaridade de ImagensMétricas de Similaridade de Imagens
Métricas de Similaridade de Imagens
 
Are You Low On Magnesium?
Are You Low On Magnesium?Are You Low On Magnesium?
Are You Low On Magnesium?
 
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
Receptor-like proteins (RLPs) and kinases are major classes of resistance gen...
 
AP WH Chapter 12 PPT
AP WH Chapter 12 PPTAP WH Chapter 12 PPT
AP WH Chapter 12 PPT
 
Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1Mary T Bogen Resume 2015-1
Mary T Bogen Resume 2015-1
 
A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...A study on the problems faced by the social science teachers in the high scho...
A study on the problems faced by the social science teachers in the high scho...
 
Apuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoriaApuntes la vida_en_la_prehistoria
Apuntes la vida_en_la_prehistoria
 
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
Sec 4N Hist (Elec) Chapter 9.2: Korean War Part 2
 
Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750Chapter 13 political transformations : Empires and encounters 1450-1750
Chapter 13 political transformations : Empires and encounters 1450-1750
 

Similaire à Lecture no 3

Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsMorteza Mahdilar
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaonyash production
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 

Similaire à Lecture no 3 (20)

Base de-datos
Base de-datosBase de-datos
Base de-datos
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Pointer
PointerPointer
Pointer
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
C++
C++C++
C++
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
901131 examples
901131 examples901131 examples
901131 examples
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
C++ Programs
C++ ProgramsC++ Programs
C++ Programs
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Dernier (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Lecture no 3

  • 1. Some Examples And Things To Remember C++ And Java
  • 2. Programe to interchange the values of two variables In C++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,num1,replace;   cout<<"entre number 1"<<endl;  cin>>num;  cout<<"entre number 2"<<endl;  cin>>num1;  replace=num;  num=num1;  num1=replace;  cout<<"after replacing "<<endl<<num<<endl;  cout<<"after replacing "<<endl<<num1;  }  public static void main(String[] args) {  int num,num1,replace;  Scanner a=new Scanner(System.in);  System.out.println("entre number 1");  num=a.nextInt();  System.out.println("entre number 2");  num1=a.nextInt();  replace=num;  num=num1;  num1=replace;  System.out.println("after replacing "+num);  System.out.println("after replacing "+num1);     } 
  • 3. Programe to find absolute of a negative number(Without if else) In C++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,num1,replace;   cout<<"entre negative number "<<endl;  cin>>num;  int abs=num*-1;   cout<<"abs value is "<<endl<<abs<<endl;   }  public static void main(String[] args) {  int num;  Scanner a=new Scanner(System.in);  System.out.println("entre negative number");  num=a.nextInt();  int abs=num*-1;  System.out.println("absolute value is "+abs);      }
  • 4. User entered 3 digit number break it in single digits and display accordingly In c++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,bre,bre1,bre2,b,c;   cout<<"entre 3 digit number "<<endl;  cin>>num;  bre=num/100;  c=num/10;  bre1=c%10;  bre2=num%10;   cout<<"first digit is "<<endl<<bre<<endl;  cout<<"Second digit is "<<endl<<bre1<<endl;  cout<<"third digit is "<<endl<<bre2<<endl;   }  public static void main(String[] args) {  // TODO code application logic here  int number,bre,bre1,bre2,b,c;  Scanner a =new Scanner(System.in);  System.out.println("entre 3 digit number");  number=a.nextInt();  bre=number/100;  c=number/10;  bre1=c%10;  bre2=number%10;  System.out.println("first digit is "+bre);  System.out.println("second digit is "+bre1);  System.out.println("third digit is "+bre2);   }
  • 5. Difference between / and % Division / Modulus %  4/2 will give 2  10/5 will give 2  15/3 will give 3  21/2 will give 10  4%2 will give 0  10%2 will give 0  15/3 will give 0  21/2 will give 5  Help full tool used to break the number in single digits
  • 6. Marks entered by user find average of these marks In c++ In Java  #include<iostream>  using namespace std;  int main()  {  int num,num1,num2;   cout<<"entre marks of sub1 "<<endl;  cin>>num;  cout<<"entre marks of sub2 "<<endl;  cin>>num1;  cout<<"entre marks of sub3 "<<endl;  cin>>num2;  int avg=(num+num1+num2)/3;   cout<<"avg is "<<endl<<avg<<endl;    }  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  int number,number1,number2;  Scanner a =new Scanner(System.in);  System.out.println("entre marks of sub 1");  number=a.nextInt();  System.out.println("entre marks of sub 2");  number1=a.nextInt();  System.out.println("entre marks of sub 3");  number2=a.nextInt();  int avg=(number+number1+number2)/3;   System.out.println("avarage is "+avg);   }   }
  • 7. Temperature in fahrenheit is input convert it into celsius In C++ In Java  #include<iostream>  using namespace std;  int main()  {  float far,cel;   cout<<"entre temperature in farenhet "<<endl;  cin>>far;   cel=(far-32)*5/9;   cout<<"temp in celseius is "<<endl<<cel<<endl;    }  */  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  double far,cel;  Scanner a =new Scanner(System.in);  System.out.println("entre temparature in farenheit ");  far=a.nextDouble();  cel=(far-32)*5/9;  System.out.println("Temp in cel is "+cel+"degree celcius");   }   }
  • 8. Ayaz basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary. In C++ In Java  #include<iostream>  using namespace std;  int main()  {  float bsal,da,hr,gsal;   cout<<"entre basic salary "<<endl;  cin>>bsal;  da=0.4*bsal;  hr=0.2*bsal;  gsal=bsal-da-hr;  cout<<"Gross salar is "<<endl<<gsal<<endl;    }  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  double bsal,da,hr,gsal;  Scanner a =new Scanner(System.in);  System.out.println("Ayaz entre your basic salary ");  bsal=a.nextInt();  da=0.4*bsal;  hr=0.2*bsal;  gsal=bsal-da-hr;  System.out.println("gross salary is"+gsal);   }   }
  • 9. If a three-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 123 then the output should be displayed as 234. In C++ In Java  #include<iostream>  using namespace std;  int main()  {  int number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;  cout<<"entre number"<<endl;  cin>>number;  bre=number/100;  nbre=bre+1;  c=number/10;  bre1=c%10;  nbre1=bre1+1;  bre2=number%10;  nbre2=bre2+1;  cout<<"after adding 1 is"<<endl;  cout<<nbre;  cout<<nbre1;  cout<<nbre2;   }  int number,bre,bre1,bre2,b,c,nbre,nbre1,nbre2;  Scanner a =new Scanner(System.in);  number=a.nextInt();  bre=number/100;  nbre=bre+1;  c=number/10;  bre1=c%10;  nbre1=bre1+1;  bre2=number%10;  nbre2=bre2+1;  System.out.println("after adding 1 is");  System.out.print(nbre);  System.out.print(nbre1);  System.out.print(nbre2);
  • 10. Radius is input from user find area In C++ In Java  #include<iostream>  using namespace std;  int main()  {  float radius,area;  cout<<"entre radius"<<endl;  cin>>radius;  area=3.14*radius*radius;  cout<<"radius is"<<endl;  cout<<area;    }  public class JavaApplication10 {  /**  * @param args the command line arguments  */  public static void main(String[] args) {  // TODO code application logic here  double radius,area;  Scanner a =new Scanner(System.in);  System.out.println("entre radius");  radius=a.nextDouble();  area=3.14*radius*radius;  System.out.println("area is"+area);    }   }
  • 11. Key points In C++ In Java  In order to give one line gap we use endl  In C++ endl will give the one line gap and cursor will go to next line  cout<<"entre radius"<<endl;  In above instruction entre ra dius will print and <<endl will provide the one line gap  Join string with variable we use string << variablename;  In order to give one line gap we use System.out.println  Here ln will give one line break if we use System.out.print it do not give one line break and print in the same line  If we want to join string with variable value we use + sign
  • 12. Thanks alot Contact me at muhammadhaseeb562@gmai l.com Mobile no:- 0336-5686312