SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Pseudo Code Practice Problems:
Listedbelowisabrief explanationof Pseudocode aswell asalistof examplesandsolutions.
Pseudo code
Pseudocode can be brokendownintofive components.
• Variables:
• Assignment:
• Input/output:
• Selection:
• Repetition:
A variable has a name, a data type, and a value. There is a location in memory associated with each
variable. A variable can be called anything or be given any name. It is considered good practice to use
variable namesthatare relevanttothe task at hand.
Assignmentisthe physical actof placinga value intoavariable.Assignmentcanbe shownusing
set= 5;
set= num+ set;
The left side is the variable a value is being stored in and the right side is where the variable is being
accessed. When a variable is assigned a value, the old value is written over with the new value so the old
value is gone. x = 5 does not mean that x is equal to 5; it means set the variable x to have the value 5.
Give x the value 5, make x equal to 5.
Input / Output both deal with an outside source (can be a user or another program) receiving or giving
information. An example would be assuming a fast food restaurant is a program. A driver (user) would
submit their order for a burger and fries (input), they would then drive to the side window and pick up
theirorderedmeal (output.)
• Output– Write / display/print
• Input– Read/ get/ input
Selection construct allows for a choice between performing an action and skipping it. It is our
conditional statements.Selectionstatementsare writtenassuch:
if ( conditional statement)
statementlist
else
statementlist
Repetitionisa construct that allowsinstructionstobe executedmultipletimes(IErepeated).
In a repetitionproblem
• Countis initialized
• Tested
• incremented
Repetitionproblemsare shownas:
while ( conditionstatement)
statementlist
Examples
Example 1: Write pseudocode that reads two numbersand multipliesthemtogether andprintout
theirproduct.
Example 2: Write pseudocode thattells a userthat the numberthey enteredisnot a 5 or a 6.
Example 3: Write pseudocode thatperformsthe following:Askauserto entera number. If the number
is between0 and 10, write the word blue.Ifthe numberis between10 and 20, write the word
red. ifthe numberis between20 and 30, write the word green. If it isany othernumber,write
that itis not a correct coloroption.
Example 4: Write pseudocode to print all multiplesof5 between1 and 100 (includingboth1 and100).
Example 5: Write pseudocode thatwill countall the evennumbersup to a userdefinedstopping
point.
Example 6: Write pseudocode thatwill performthe following.
a) Readin 5 separate numbers.
b) Calculate the average of the five numbers.
c) Findthe smallest(minimum) andlargest(maximum)of the five enterednumbers.
d) Write outthe resultsfoundfromstepsband c witha message describingwhattheyare
Homework1: Write pseudocode thatreads inthree numbersandwritesthemall insortedorder.
Homework2: Write pseudocode thatwill calculate arunningsum.A userwill enternumbersthatwill
be addedto the sum and whenanegative numberisencountered,stopaddingnumbersand
write outthe final result.
Solutions
Example 1: Write pseudocode thatreadstwo numbersandmultipliesthemtogetherandprintout their
product.
Pseudocode
Readnum1 , num2
Setmulti to num1*num2
Write multi
Ch code
intnum1, num2,multi;
cin>>num1>>num2;
multi = num1 * num2;
cout<<multi<<endl;
Example 2: Write pseudocode thattellsauser that the numbertheyenteredisnota5 or a 6.
Example 2 Solution1:
PseudoCode: CH code:
Readisfive
If(isfive =5)
Write "your numberis5"
Else if (isfive =6)
Write "your numberis6"
Else
Write "your numberisnot5 or 6"
intisfive;
cin>> isfive;
if(isfive==5)
{ cout<<"yournumberis5"; }
else if(isfive ==6)
{ cout<<"yournumberis6"; }
else
{ cout<<"yournumberisnot 5 or 6"; }
Example 2 Solution2:
PseudoCode:
Readisfive
If(isfive =5 or isfive =6)
Write "your numberisa 5 or 6"
Else
Write "your numberisnot5 or 6"
CH code:
intisfive;
cin>> isfive;
if(isfive==5 || isfive ==6)
{ cout<<"yournumberis5 or 6"; }
else
{ cout<<"yournumberisnot 5 or 6"; }
Example 2 Solution3:
PseudoCode:
Readisfive
If(isfive isnot5 andisfive isnot6)
Write "your numberisnot5 or 6"
CH code:
intisfive;
cin>> isfive;
if(isfive!=5 && isfive !=6)
{ cout<<"yournumberisnot 5 or 6"; }
Example 3: Write pseudocode thatperformsthe following:Askauserto entera number.If the number
isbetween0and 10, write the wordblue.If the numberisbetween10and 20, write the word
red.if the numberisbetween20and 30, write the word green.If itisany othernumber,write
that itis not a correct coloroption.
PseudoCode:
Write "Please enteranumber"
Readcolornum
If (colornum>0 andcolornum<= 10)
Write blue
else If (colornum>0 andcolornum<= 10)
Write blue
else If (colornum>0 andcolornum<= 10)
Write blue
else
Write "not a correct color option"
CH code:
intcolornum;
cout<<"Please enteranumber"
cin>> colornum;
if(colornum>0 && colornum<= 10)
{ cout<<"blue"; }
else if(colornum>0 && colornum<= 10)
{ cout<<"blue";}
else if(colornum>0 && colornum<= 10)
{ cout<<"blue"; }
else
{ cout<<"not a correct coloroption" }
Example 4: Write pseudocode toprintall multiplesof 5between1and 100 (includingboth1and 100).
PseudoCode:
Setx to 1
While(x <20)
write x
x = x*5
CH code:
intx = 1;
cin>>x;
while(x<20)
{ cout<<x;
x = x*5;
}
Example 5: Write pseudocode thatwill countall the evennumbersuptoa userdefinedstoppingpoint.
For example,saywe wanttosee the first5 evennumbersstartingfrom0.
well,we knowthatevensnumbersare 0,2, 4, etc.
The first5 evennumbersare 0, 2, 4, 6, 8.
The first8 evennumbersare 0, 2, 4, 6, 8 ,10 ,12, 16
Example 5 solution1:
PseudoCode:
Readcount
Setx to 0;
While(x <count)
Set eventoeven+ 2
x = x + 1
write even
CH code:
intx, count,even;
x = 0;
even= 0;
cin>>count;
while(x<count)
{ cout<<even;
even= even+2;
x = x+1;
}
Example 5 solution2:
PseudoCode:
Readcount
Setx to 0;
While(x <count)
Set eventoeven+ 2
x = x + 1
write even
CH code:
intx, count,even;
cout<<"0";
x = 1;
cin>>count;
while(x<count)
{ cout<<x*2;
x = x+1;
}
Example 6: Write pseudocode thatwill performthe following.
a) Readin 5 separate numbers.
b) Calculate the average of the five numbers.
c) Findthe smallest(minimum) andlargest(maximum)of the five enterednumbers.
d) Write outthe resultsfoundfromstepsband c witha message describingwhattheyare.
PseudoCode:
Write "please enter5numbers"
Readn1,n2,n3,n4,n5
Write "The average is"
Setavg to (n1+n2+n3+n4+n5)/5
Write avg
If(n1< n2)
Setmax to n2
Else
Setmax to n1
If(n3> max)
Setmax to n3
If(n4> max)
Setmax to n4
If(n5> max)
Setmax to n5
Write "The max is"
Write max
If(n1> n2)
Setminto n2
Else
Setminto n1
If(n3< min)
Setminto n3
If(n4< min)
Setminto n4
If(n5< min)
Setminto n5
Write "The min is"
Write min
CH code:
cout<<"please enter5numbers";
intn1,n2,n3,n4,n5;
cin>>n1>>n2>>n3>>n4>>n5;
intavg = (n1+n2+n3+n4+n5)/5;
cout<<"The average is"<<avg;
intmin,max;
if(n1<n2)
max=n2;
else
max=n1;
if(n3>max)
max=n3;
if(n4>max)
max=n4;
if(n5>max)
max=n5;
cout<<"The max is"<<max;
if(n1>n2)
min=n2;
else
min=n1;
if(n3<min)
min=n3;
if(n4<min)
min=n4;
if(n5<min)
min=n5;
cout<<"The minis"<<min;
Homework1: Write pseudocode thatreads inthree numbersandwritesthemall insortedorder.
Homework1 solution1:
PseudoCode:
Readnum1, num2,num3
If (num1 < num2)
If(num2< num3)
Write num1 ,num2, num3
Else
If(num3< num1)
Write num3,num1, num2
Else
Write num1,num3, num2
else
If(num1< num3)
Write num2 ,num1, num3
Else
If(num3< num2)
Write num3,num2, num1
Else
Write num2,num3, num1
CH code:
intnum1, num2,num3;
cin>> num1>>num2>>num3;
if (num1 < num2)
{ if(num2< num3)
{ Cout<< num1<<" "<<num2<<" "<<num3; }
else
{ if(num3< num1)
{ Cout<< num3<<" "<<num2<<" "<<num2; }
else
{ Cout<< num1<<" "<<num3<<" "<<num2; }
}
}
else
{ If(num1< num3)
{ Cout<< num2<<" "<<num1<<" "<<num3; }
else
{ If(num3< num2)
{ Cout<< num3<<" "<<num2<<" "<<num1; }
else
{ Cout<< num2<<" "<<num3<<" "<<num1; }
}
}
Homework1 solution2:
PseudoCode:
Readnum1, num2,num3
If (num1 < num2 < num3)
Write num1 , num2, num3
else If (num1< num3 < num2)
Write num1 , num2, num3
else If (num2< num1 < num3)
Write num2 , num1, num3
else If (num2< num3 < num1)
Write num2 , num3, num1
else If (num3< num1 < num2)
Write num3 , num1, num2
else If (num3< num2< num1)
Write num3 , num2, num1
CH code:
intnum1, num2;
cin>> num1>>num2>>num3;
if(num1< num2 && num2 < num3&& num1 < num3)
{ cout<<num1<<" "<<num2<<" "<<num3; }
else if(num1< num2 && num2 > num3&& num1 < num3)
{ cout<<num1<<" "<<num3<<" "<<num2; }
else if(num1> num2 && num2 < num3&& num1 < num3)
{ cout<<num2<<" "<<num1<<" "<<num3; }
else if(num1> num2 && num2 < num3&& num1 > num3)
{ cout<<num2<<" "<<num3<<" "<<num1; }
else if(num1< num2 && num2 > num3&& num1 > num3)
{ cout<<num3<<" "<<num1<<" "<<num2; }
else if(num1> num2 && num2 > num3&& num1 > num3)
{ cout<<num3<<" "<<num2<<" "<<num1; }
Homework2: Write pseudocode thatwill calculate arunningsum.A userwill enternumbersthatwill
be addedto the sum and whenanegative numberisencountered,stopaddingnumbersand
write outthe final result.
Pseudo Code:
Readx
Setsum to 0;
While(x >=0)
Set sumto x + sum
Read x
CH code:
intx, sum;
sum= 0;
cin>>x;
while(x>=0)
{ sum = sum + x
cin>>x;
}
C - Basic Introduction
The C is a general-purpose, procedural, imperative computer programming language
developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
system.
C is the most widely used computer language.
C is a general-purpose high level language that was originally developed by Dennis Ritchie for
the Unix operating system. It was first implemented on the Digital Eqquipment Corporation
PDP-11 computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C language. C
has now become a widely used professional language for various reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
• It can be compiled on a variety of computers.
Facts about C
• C was invented to write an operating system called UNIX.
• C is a successor of B language which was introduced around 1970
• The language was formalized in 1988 by the American National Standard Institue
(ANSI).
• By 1973 UNIX OS almost totally written in C.
• Today C is the most widely used System Programming Language.
• Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs that make-up the
operating system. C was adoped as a system development language because it produces code that
runs nearly as fast as code written in assembly language. Some examples of the use of C might
be:
• Operating Systems
• Language Compilers
• Assemblers
• Text Editors
• Print Spoolers
• Network Drivers
• Modern Programs
• Data Bases
• Language Interpreters
• Utilities
C Program File
All the C programs are writen into text files with extension ".c" for example hello.c. You can use
"vi" editor to write your C program into a file.
This tutorial assumes that you know how to edit a text file and how to write programming
insturctions inside a program file.
C Compilers
When you write any program in C language then to run that program you need to compile that
program using a C Compiler which converts your program into a language understandable by a
computer. This is called machine language (ie. binary format). So before proceeding, make sure
you have C Compiler available at your computer. It comes alongwith all flavors of Unix and
Linux.
If you are working over Unix or Linux then you can type gcc -v or cc -v and check the result.
You can ask your system administrator or you can take help from anyone to identify an available
C Compiler at your computer.
If you don't have C compiler installed at your computer then you can use below given link to
download a GNU C Compiler and use it.
To know more about compilation you can go through this small tutorial Learn HYPERLINK
"http://www.tutorialspoint.com/makefile/index.htm"Makefile.
A C programbasically has the following form:
• P reprocessor Commands
• Functions
• V ariables
• Statements & Expressions
• C omments
The following program is written in the C programming language. Open a text file hello.c using vi editor and put the following lines inside
that file.
#include <stdio.h>
int main()
{
/* My first program */
printf("Hello, World! n");
return 0;
}
Preprocessor Commands: T hese commands tells the compiler to do preprocessing before doing actual compilation. Like #include
<stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. You will learn more
about C Preprocessors in C Preprocessors session.
Functions: are main building blocks of any C Program. Every C Program will have one or more functions and there is one mandatory function
which is called main() function. This function is prefixed with keyword int which means this function returns an integer value when it exits.
T his integer value is retured using return statement.
The C Programming language provides a set of built-in functions. In the above example printf()is a C built-in function which is used to print
anything on the screen. Check Builtin functionsection for more detail.
Y ou will learnhow to write yourown functions and use them in Using Function session.
Variables: are used to hold numbers, strings and complex data for manipulation. Y ou will learn in detail about variables in C Variable Types.
Statements & Expressions : Expressions combine variables and constants to create new values . Statements are expressions, assignments,
functioncalls, or control flow statements whichmake up C programs.
Comments: are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/ as given in the
example above. A comment canspan throughmultiple lines.
Note the followings
• C is a case sensitive programming language. It means in C printf and Printf will have different meanings.
• C has a free-formline structure. End of eachC statement must be marked with a semicolon.
• M ultiple statements can be one the same line.
• White Spaces (ie tab space and space bar ) are ignored.
• Statements cancontinue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files name. Assuming your compiler's name is cc and progra m file
name is hello.c, give following command at U nix prompt.
$cc hello.c
This will produce a binary file called a.out and an object file hello.o in your current directory. Here a.out is your first program which you will
run at Unix prompt like any other system program. If you don't like the name a.out then you can produce a binary file with your own name by
using -o option while compiling C program. See an example below
$cc -o hello hello.c
Now you will get a binary with name hello. Execute this program at Unix prompt but before executing / running this program make sure that
it has execute permissionset. If youdon't know what is execute permissionthen just follow these two steps
$chmod 755 hello
$./hello
This will produce following result
Hello, World
C ongratulations!! youhave writtenyour first programin "C". Now believe me its not difficult to learn "C".

Weitere ähnliche Inhalte

Was ist angesagt?

Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...
Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...
Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...Waqas Afzal
 
Turbo equalization
Turbo equalizationTurbo equalization
Turbo equalizationNisha Menon K
 
Channel capacity
Channel capacityChannel capacity
Channel capacityPALLAB DAS
 
Combinational circuit
Combinational circuitCombinational circuit
Combinational circuitSatya P. Joshi
 
Counters In Digital Logic Design
Counters In Digital Logic DesignCounters In Digital Logic Design
Counters In Digital Logic DesignSyed Abdul Mutaal
 
Combinational circuits
Combinational circuits Combinational circuits
Combinational circuits DrSonali Vyas
 
Time Division Multiplexing
Time Division MultiplexingTime Division Multiplexing
Time Division MultiplexingSpandit Lenka
 
Stack organization
Stack organizationStack organization
Stack organizationchauhankapil
 
Flipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflopsFlipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflopsstudent
 
Decoder Full Presentation
Decoder Full Presentation Decoder Full Presentation
Decoder Full Presentation Adeel Rasheed
 
Overview of sampling
Overview of samplingOverview of sampling
Overview of samplingSagar Kumar
 
Multiplexing
MultiplexingMultiplexing
MultiplexingAman Jaiswal
 
Media Access Control
Media Access ControlMedia Access Control
Media Access ControlVijayaLakshmi514
 
4 bit Binary counter
4 bit Binary counter4 bit Binary counter
4 bit Binary counterJainee Solanki
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDLanand hd
 

Was ist angesagt? (20)

Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...
Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...
Sampling Theorem, Quantization Noise and its types, PCM, Channel Capacity, Ny...
 
Turbo equalization
Turbo equalizationTurbo equalization
Turbo equalization
 
Bus system
Bus systemBus system
Bus system
 
Channel capacity
Channel capacityChannel capacity
Channel capacity
 
Combinational circuit
Combinational circuitCombinational circuit
Combinational circuit
 
Multiplexers
MultiplexersMultiplexers
Multiplexers
 
Counters In Digital Logic Design
Counters In Digital Logic DesignCounters In Digital Logic Design
Counters In Digital Logic Design
 
Combinational circuits
Combinational circuits Combinational circuits
Combinational circuits
 
Time Division Multiplexing
Time Division MultiplexingTime Division Multiplexing
Time Division Multiplexing
 
Stack organization
Stack organizationStack organization
Stack organization
 
Flipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflopsFlipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflops
 
Decoder Full Presentation
Decoder Full Presentation Decoder Full Presentation
Decoder Full Presentation
 
Overview of sampling
Overview of samplingOverview of sampling
Overview of sampling
 
Logic gates
Logic gatesLogic gates
Logic gates
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Multiplexing
MultiplexingMultiplexing
Multiplexing
 
Media Access Control
Media Access ControlMedia Access Control
Media Access Control
 
Presentation On Flip-Flop
Presentation On Flip-FlopPresentation On Flip-Flop
Presentation On Flip-Flop
 
4 bit Binary counter
4 bit Binary counter4 bit Binary counter
4 bit Binary counter
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
 

Andere mochten auch

Change management for leaders to achieve business competitive
Change management for leaders to achieve business competitiveChange management for leaders to achieve business competitive
Change management for leaders to achieve business competitiveRidwan Ibrahim
 
Result assessment re alignment culture report Danareksa
Result assessment re alignment culture report DanareksaResult assessment re alignment culture report Danareksa
Result assessment re alignment culture report DanareksaRidwan Ibrahim
 
Avoid the resistance on change management
Avoid the resistance on change managementAvoid the resistance on change management
Avoid the resistance on change managementRidwan Ibrahim
 
Investigating the flexibility of selfish herd theory under varying conditions...
Investigating the flexibility of selfish herd theory under varying conditions...Investigating the flexibility of selfish herd theory under varying conditions...
Investigating the flexibility of selfish herd theory under varying conditions...Andy Gray
 
Leadership quality of abdul kalam
Leadership quality of abdul kalamLeadership quality of abdul kalam
Leadership quality of abdul kalamKeval Goyani
 
Implementation Strategy for Research and Community Service of University
Implementation Strategy for Research and Community Service of UniversityImplementation Strategy for Research and Community Service of University
Implementation Strategy for Research and Community Service of UniversityRidwan Ibrahim
 
Prevention Strategy for Money Laundering
Prevention Strategy for Money LaunderingPrevention Strategy for Money Laundering
Prevention Strategy for Money LaunderingRidwan Ibrahim
 
Scentroid Toms Capabilities ENGLISH
Scentroid Toms Capabilities ENGLISHScentroid Toms Capabilities ENGLISH
Scentroid Toms Capabilities ENGLISHSidarta Medina
 
Driver Hire Australia Brochure
Driver Hire Australia BrochureDriver Hire Australia Brochure
Driver Hire Australia BrochureDriver Hire Sydney .
 
Alignment HRBP with ISO 41000-2015 to Achieve Business on Globalization
Alignment HRBP with ISO 41000-2015 to Achieve Business on GlobalizationAlignment HRBP with ISO 41000-2015 to Achieve Business on Globalization
Alignment HRBP with ISO 41000-2015 to Achieve Business on GlobalizationRidwan Ibrahim
 
Resume shruti kapoor- ASMs
Resume shruti kapoor- ASMsResume shruti kapoor- ASMs
Resume shruti kapoor- ASMsShruti Kapoor Arya
 
DISC-SIDARTA_MEDINA
DISC-SIDARTA_MEDINADISC-SIDARTA_MEDINA
DISC-SIDARTA_MEDINASidarta Medina
 
Jimbo | Pitch Deck
Jimbo | Pitch DeckJimbo | Pitch Deck
Jimbo | Pitch DeckJimbo
 
Change management towards sustainable business growth (aligned with ISO 41000...
Change management towards sustainable business growth (aligned with ISO 41000...Change management towards sustainable business growth (aligned with ISO 41000...
Change management towards sustainable business growth (aligned with ISO 41000...Ridwan Ibrahim
 
Resume for 2016
Resume for 2016Resume for 2016
Resume for 2016Steve Kennedy
 
Hotel Vyas & Nirvana Yoga
Hotel Vyas & Nirvana YogaHotel Vyas & Nirvana Yoga
Hotel Vyas & Nirvana YogaYogi Vyas
 
HVS-UnderstandingOnlineDistributionChannels
HVS-UnderstandingOnlineDistributionChannelsHVS-UnderstandingOnlineDistributionChannels
HVS-UnderstandingOnlineDistributionChannelsJuan Pablo Duran
 
Talent Developing Strategy For Human Capital To Achieve ROI
Talent Developing Strategy For Human Capital To Achieve ROITalent Developing Strategy For Human Capital To Achieve ROI
Talent Developing Strategy For Human Capital To Achieve ROIRidwan Ibrahim
 

Andere mochten auch (20)

Change management for leaders to achieve business competitive
Change management for leaders to achieve business competitiveChange management for leaders to achieve business competitive
Change management for leaders to achieve business competitive
 
Result assessment re alignment culture report Danareksa
Result assessment re alignment culture report DanareksaResult assessment re alignment culture report Danareksa
Result assessment re alignment culture report Danareksa
 
Avoid the resistance on change management
Avoid the resistance on change managementAvoid the resistance on change management
Avoid the resistance on change management
 
Investigating the flexibility of selfish herd theory under varying conditions...
Investigating the flexibility of selfish herd theory under varying conditions...Investigating the flexibility of selfish herd theory under varying conditions...
Investigating the flexibility of selfish herd theory under varying conditions...
 
Leadership quality of abdul kalam
Leadership quality of abdul kalamLeadership quality of abdul kalam
Leadership quality of abdul kalam
 
Implementation Strategy for Research and Community Service of University
Implementation Strategy for Research and Community Service of UniversityImplementation Strategy for Research and Community Service of University
Implementation Strategy for Research and Community Service of University
 
Resume
ResumeResume
Resume
 
Resume 150927
Resume 150927Resume 150927
Resume 150927
 
Prevention Strategy for Money Laundering
Prevention Strategy for Money LaunderingPrevention Strategy for Money Laundering
Prevention Strategy for Money Laundering
 
Scentroid Toms Capabilities ENGLISH
Scentroid Toms Capabilities ENGLISHScentroid Toms Capabilities ENGLISH
Scentroid Toms Capabilities ENGLISH
 
Driver Hire Australia Brochure
Driver Hire Australia BrochureDriver Hire Australia Brochure
Driver Hire Australia Brochure
 
Alignment HRBP with ISO 41000-2015 to Achieve Business on Globalization
Alignment HRBP with ISO 41000-2015 to Achieve Business on GlobalizationAlignment HRBP with ISO 41000-2015 to Achieve Business on Globalization
Alignment HRBP with ISO 41000-2015 to Achieve Business on Globalization
 
Resume shruti kapoor- ASMs
Resume shruti kapoor- ASMsResume shruti kapoor- ASMs
Resume shruti kapoor- ASMs
 
DISC-SIDARTA_MEDINA
DISC-SIDARTA_MEDINADISC-SIDARTA_MEDINA
DISC-SIDARTA_MEDINA
 
Jimbo | Pitch Deck
Jimbo | Pitch DeckJimbo | Pitch Deck
Jimbo | Pitch Deck
 
Change management towards sustainable business growth (aligned with ISO 41000...
Change management towards sustainable business growth (aligned with ISO 41000...Change management towards sustainable business growth (aligned with ISO 41000...
Change management towards sustainable business growth (aligned with ISO 41000...
 
Resume for 2016
Resume for 2016Resume for 2016
Resume for 2016
 
Hotel Vyas & Nirvana Yoga
Hotel Vyas & Nirvana YogaHotel Vyas & Nirvana Yoga
Hotel Vyas & Nirvana Yoga
 
HVS-UnderstandingOnlineDistributionChannels
HVS-UnderstandingOnlineDistributionChannelsHVS-UnderstandingOnlineDistributionChannels
HVS-UnderstandingOnlineDistributionChannels
 
Talent Developing Strategy For Human Capital To Achieve ROI
Talent Developing Strategy For Human Capital To Achieve ROITalent Developing Strategy For Human Capital To Achieve ROI
Talent Developing Strategy For Human Capital To Achieve ROI
 

Ă„hnlich wie Pseudo code practice problems+ c basics

OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxgerardkortney
 
loopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfloopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfDheeravathBinduMadha
 
2 2 rational numbers trout09
2 2 rational numbers trout092 2 rational numbers trout09
2 2 rational numbers trout09Akshat Jain
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdfRohitSindhu10
 
C important questions
C important questionsC important questions
C important questionsJYOTI RANJAN PAL
 
1 ECE 175 Computer Programming for Engineering Applica.docx
1  ECE 175 Computer Programming for Engineering Applica.docx1  ECE 175 Computer Programming for Engineering Applica.docx
1 ECE 175 Computer Programming for Engineering Applica.docxoswald1horne84988
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in pythonRaginiJain21
 
10 template code program
10 template code program10 template code program
10 template code programBint EL-maghrabi
 
Python programing
Python programingPython programing
Python programinghamzagame
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
 

Ă„hnlich wie Pseudo code practice problems+ c basics (20)

OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
algorithm
algorithmalgorithm
algorithm
 
loopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdfloopingstatementinpython-210628184047 (1).pdf
loopingstatementinpython-210628184047 (1).pdf
 
2 2 rational numbers trout09
2 2 rational numbers trout092 2 rational numbers trout09
2 2 rational numbers trout09
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34đź’­.pdf
python 34đź’­.pdfpython 34đź’­.pdf
python 34đź’­.pdf
 
C code examples
C code examplesC code examples
C code examples
 
C important questions
C important questionsC important questions
C important questions
 
1 ECE 175 Computer Programming for Engineering Applica.docx
1  ECE 175 Computer Programming for Engineering Applica.docx1  ECE 175 Computer Programming for Engineering Applica.docx
1 ECE 175 Computer Programming for Engineering Applica.docx
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
10 template code program
10 template code program10 template code program
10 template code program
 
Python programing
Python programingPython programing
Python programing
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Python
PythonPython
Python
 
Programming egs
Programming egs Programming egs
Programming egs
 
Pseudocode
PseudocodePseudocode
Pseudocode
 

Pseudo code practice problems+ c basics

  • 1. Pseudo Code Practice Problems: Listedbelowisabrief explanationof Pseudocode aswell asalistof examplesandsolutions. Pseudo code Pseudocode can be brokendownintofive components. • Variables: • Assignment: • Input/output: • Selection: • Repetition: A variable has a name, a data type, and a value. There is a location in memory associated with each variable. A variable can be called anything or be given any name. It is considered good practice to use variable namesthatare relevanttothe task at hand. Assignmentisthe physical actof placinga value intoavariable.Assignmentcanbe shownusing set= 5; set= num+ set; The left side is the variable a value is being stored in and the right side is where the variable is being accessed. When a variable is assigned a value, the old value is written over with the new value so the old value is gone. x = 5 does not mean that x is equal to 5; it means set the variable x to have the value 5. Give x the value 5, make x equal to 5. Input / Output both deal with an outside source (can be a user or another program) receiving or giving information. An example would be assuming a fast food restaurant is a program. A driver (user) would submit their order for a burger and fries (input), they would then drive to the side window and pick up theirorderedmeal (output.) • Output– Write / display/print • Input– Read/ get/ input Selection construct allows for a choice between performing an action and skipping it. It is our conditional statements.Selectionstatementsare writtenassuch: if ( conditional statement) statementlist else statementlist Repetitionisa construct that allowsinstructionstobe executedmultipletimes(IErepeated). In a repetitionproblem • Countis initialized • Tested • incremented Repetitionproblemsare shownas: while ( conditionstatement)
  • 2. statementlist Examples Example 1: Write pseudocode that reads two numbersand multipliesthemtogether andprintout theirproduct. Example 2: Write pseudocode thattells a userthat the numberthey enteredisnot a 5 or a 6. Example 3: Write pseudocode thatperformsthe following:Askauserto entera number. If the number is between0 and 10, write the word blue.Ifthe numberis between10 and 20, write the word red. ifthe numberis between20 and 30, write the word green. If it isany othernumber,write that itis not a correct coloroption. Example 4: Write pseudocode to print all multiplesof5 between1 and 100 (includingboth1 and100). Example 5: Write pseudocode thatwill countall the evennumbersup to a userdefinedstopping point. Example 6: Write pseudocode thatwill performthe following. a) Readin 5 separate numbers. b) Calculate the average of the five numbers. c) Findthe smallest(minimum) andlargest(maximum)of the five enterednumbers. d) Write outthe resultsfoundfromstepsband c witha message describingwhattheyare Homework1: Write pseudocode thatreads inthree numbersandwritesthemall insortedorder. Homework2: Write pseudocode thatwill calculate arunningsum.A userwill enternumbersthatwill be addedto the sum and whenanegative numberisencountered,stopaddingnumbersand write outthe final result. Solutions Example 1: Write pseudocode thatreadstwo numbersandmultipliesthemtogetherandprintout their product. Pseudocode Readnum1 , num2 Setmulti to num1*num2 Write multi Ch code intnum1, num2,multi; cin>>num1>>num2; multi = num1 * num2; cout<<multi<<endl; Example 2: Write pseudocode thattellsauser that the numbertheyenteredisnota5 or a 6. Example 2 Solution1: PseudoCode: CH code:
  • 3. Readisfive If(isfive =5) Write "your numberis5" Else if (isfive =6) Write "your numberis6" Else Write "your numberisnot5 or 6" intisfive; cin>> isfive; if(isfive==5) { cout<<"yournumberis5"; } else if(isfive ==6) { cout<<"yournumberis6"; } else { cout<<"yournumberisnot 5 or 6"; } Example 2 Solution2: PseudoCode: Readisfive If(isfive =5 or isfive =6) Write "your numberisa 5 or 6" Else Write "your numberisnot5 or 6" CH code: intisfive; cin>> isfive; if(isfive==5 || isfive ==6) { cout<<"yournumberis5 or 6"; } else { cout<<"yournumberisnot 5 or 6"; } Example 2 Solution3: PseudoCode: Readisfive If(isfive isnot5 andisfive isnot6) Write "your numberisnot5 or 6" CH code: intisfive; cin>> isfive; if(isfive!=5 && isfive !=6) { cout<<"yournumberisnot 5 or 6"; } Example 3: Write pseudocode thatperformsthe following:Askauserto entera number.If the number isbetween0and 10, write the wordblue.If the numberisbetween10and 20, write the word red.if the numberisbetween20and 30, write the word green.If itisany othernumber,write that itis not a correct coloroption. PseudoCode: Write "Please enteranumber" Readcolornum If (colornum>0 andcolornum<= 10) Write blue else If (colornum>0 andcolornum<= 10) Write blue else If (colornum>0 andcolornum<= 10) Write blue else Write "not a correct color option" CH code: intcolornum; cout<<"Please enteranumber" cin>> colornum; if(colornum>0 && colornum<= 10) { cout<<"blue"; } else if(colornum>0 && colornum<= 10) { cout<<"blue";} else if(colornum>0 && colornum<= 10) { cout<<"blue"; } else { cout<<"not a correct coloroption" }
  • 4. Example 4: Write pseudocode toprintall multiplesof 5between1and 100 (includingboth1and 100). PseudoCode: Setx to 1 While(x <20) write x x = x*5 CH code: intx = 1; cin>>x; while(x<20) { cout<<x; x = x*5; } Example 5: Write pseudocode thatwill countall the evennumbersuptoa userdefinedstoppingpoint. For example,saywe wanttosee the first5 evennumbersstartingfrom0. well,we knowthatevensnumbersare 0,2, 4, etc. The first5 evennumbersare 0, 2, 4, 6, 8. The first8 evennumbersare 0, 2, 4, 6, 8 ,10 ,12, 16 Example 5 solution1: PseudoCode: Readcount Setx to 0; While(x <count) Set eventoeven+ 2 x = x + 1 write even CH code: intx, count,even; x = 0; even= 0; cin>>count; while(x<count) { cout<<even; even= even+2; x = x+1; } Example 5 solution2: PseudoCode: Readcount Setx to 0; While(x <count) Set eventoeven+ 2 x = x + 1 write even CH code: intx, count,even; cout<<"0"; x = 1; cin>>count; while(x<count) { cout<<x*2; x = x+1; }
  • 5. Example 6: Write pseudocode thatwill performthe following. a) Readin 5 separate numbers. b) Calculate the average of the five numbers. c) Findthe smallest(minimum) andlargest(maximum)of the five enterednumbers. d) Write outthe resultsfoundfromstepsband c witha message describingwhattheyare. PseudoCode: Write "please enter5numbers" Readn1,n2,n3,n4,n5 Write "The average is" Setavg to (n1+n2+n3+n4+n5)/5 Write avg If(n1< n2) Setmax to n2 Else Setmax to n1 If(n3> max) Setmax to n3 If(n4> max) Setmax to n4 If(n5> max) Setmax to n5 Write "The max is" Write max If(n1> n2) Setminto n2 Else Setminto n1 If(n3< min) Setminto n3 If(n4< min) Setminto n4 If(n5< min) Setminto n5 Write "The min is" Write min CH code: cout<<"please enter5numbers"; intn1,n2,n3,n4,n5; cin>>n1>>n2>>n3>>n4>>n5; intavg = (n1+n2+n3+n4+n5)/5; cout<<"The average is"<<avg; intmin,max; if(n1<n2) max=n2; else max=n1; if(n3>max) max=n3; if(n4>max) max=n4; if(n5>max) max=n5; cout<<"The max is"<<max; if(n1>n2) min=n2; else min=n1; if(n3<min) min=n3; if(n4<min) min=n4; if(n5<min) min=n5; cout<<"The minis"<<min; Homework1: Write pseudocode thatreads inthree numbersandwritesthemall insortedorder.
  • 6. Homework1 solution1: PseudoCode: Readnum1, num2,num3 If (num1 < num2) If(num2< num3) Write num1 ,num2, num3 Else If(num3< num1) Write num3,num1, num2 Else Write num1,num3, num2 else If(num1< num3) Write num2 ,num1, num3 Else If(num3< num2) Write num3,num2, num1 Else Write num2,num3, num1 CH code: intnum1, num2,num3; cin>> num1>>num2>>num3; if (num1 < num2) { if(num2< num3) { Cout<< num1<<" "<<num2<<" "<<num3; } else { if(num3< num1) { Cout<< num3<<" "<<num2<<" "<<num2; } else { Cout<< num1<<" "<<num3<<" "<<num2; } } } else { If(num1< num3) { Cout<< num2<<" "<<num1<<" "<<num3; } else { If(num3< num2) { Cout<< num3<<" "<<num2<<" "<<num1; } else { Cout<< num2<<" "<<num3<<" "<<num1; } } } Homework1 solution2: PseudoCode: Readnum1, num2,num3 If (num1 < num2 < num3) Write num1 , num2, num3 else If (num1< num3 < num2) Write num1 , num2, num3 else If (num2< num1 < num3) Write num2 , num1, num3 else If (num2< num3 < num1) Write num2 , num3, num1 else If (num3< num1 < num2) Write num3 , num1, num2 else If (num3< num2< num1) Write num3 , num2, num1 CH code: intnum1, num2; cin>> num1>>num2>>num3; if(num1< num2 && num2 < num3&& num1 < num3) { cout<<num1<<" "<<num2<<" "<<num3; } else if(num1< num2 && num2 > num3&& num1 < num3) { cout<<num1<<" "<<num3<<" "<<num2; } else if(num1> num2 && num2 < num3&& num1 < num3) { cout<<num2<<" "<<num1<<" "<<num3; } else if(num1> num2 && num2 < num3&& num1 > num3) { cout<<num2<<" "<<num3<<" "<<num1; } else if(num1< num2 && num2 > num3&& num1 > num3) { cout<<num3<<" "<<num1<<" "<<num2; } else if(num1> num2 && num2 > num3&& num1 > num3) { cout<<num3<<" "<<num2<<" "<<num1; }
  • 7. Homework2: Write pseudocode thatwill calculate arunningsum.A userwill enternumbersthatwill be addedto the sum and whenanegative numberisencountered,stopaddingnumbersand write outthe final result. Pseudo Code: Readx Setsum to 0; While(x >=0) Set sumto x + sum Read x CH code: intx, sum; sum= 0; cin>>x; while(x>=0) { sum = sum + x cin>>x; } C - Basic Introduction The C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. C is the most widely used computer language. C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Eqquipment Corporation PDP-11 computer in 1972. The Unix operating system and virtually all Unix applications are written in the C language. C has now become a widely used professional language for various reasons. • Easy to learn • Structured language • It produces efficient programs. • It can handle low-level activities. • It can be compiled on a variety of computers. Facts about C • C was invented to write an operating system called UNIX. • C is a successor of B language which was introduced around 1970 • The language was formalized in 1988 by the American National Standard Institue (ANSI). • By 1973 UNIX OS almost totally written in C. • Today C is the most widely used System Programming Language. • Most of the state of the art software have been implemented using C
  • 8. Why to use C ? C was initially used for system development work, in particular the programs that make-up the operating system. C was adoped as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be: • Operating Systems • Language Compilers • Assemblers • Text Editors • Print Spoolers • Network Drivers • Modern Programs • Data Bases • Language Interpreters • Utilities C Program File All the C programs are writen into text files with extension ".c" for example hello.c. You can use "vi" editor to write your C program into a file. This tutorial assumes that you know how to edit a text file and how to write programming insturctions inside a program file. C Compilers When you write any program in C language then to run that program you need to compile that program using a C Compiler which converts your program into a language understandable by a computer. This is called machine language (ie. binary format). So before proceeding, make sure you have C Compiler available at your computer. It comes alongwith all flavors of Unix and Linux. If you are working over Unix or Linux then you can type gcc -v or cc -v and check the result. You can ask your system administrator or you can take help from anyone to identify an available C Compiler at your computer. If you don't have C compiler installed at your computer then you can use below given link to download a GNU C Compiler and use it. To know more about compilation you can go through this small tutorial Learn HYPERLINK "http://www.tutorialspoint.com/makefile/index.htm"Makefile. A C programbasically has the following form: • P reprocessor Commands • Functions • V ariables
  • 9. • Statements & Expressions • C omments The following program is written in the C programming language. Open a text file hello.c using vi editor and put the following lines inside that file. #include <stdio.h> int main() { /* My first program */ printf("Hello, World! n"); return 0; } Preprocessor Commands: T hese commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. You will learn more about C Preprocessors in C Preprocessors session. Functions: are main building blocks of any C Program. Every C Program will have one or more functions and there is one mandatory function which is called main() function. This function is prefixed with keyword int which means this function returns an integer value when it exits. T his integer value is retured using return statement. The C Programming language provides a set of built-in functions. In the above example printf()is a C built-in function which is used to print anything on the screen. Check Builtin functionsection for more detail. Y ou will learnhow to write yourown functions and use them in Using Function session. Variables: are used to hold numbers, strings and complex data for manipulation. Y ou will learn in detail about variables in C Variable Types. Statements & Expressions : Expressions combine variables and constants to create new values . Statements are expressions, assignments, functioncalls, or control flow statements whichmake up C programs. Comments: are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/ as given in the example above. A comment canspan throughmultiple lines. Note the followings • C is a case sensitive programming language. It means in C printf and Printf will have different meanings. • C has a free-formline structure. End of eachC statement must be marked with a semicolon. • M ultiple statements can be one the same line. • White Spaces (ie tab space and space bar ) are ignored. • Statements cancontinue over multiple lines. C Program Compilation To compile a C program you would have to Compiler name and program files name. Assuming your compiler's name is cc and progra m file name is hello.c, give following command at U nix prompt. $cc hello.c This will produce a binary file called a.out and an object file hello.o in your current directory. Here a.out is your first program which you will run at Unix prompt like any other system program. If you don't like the name a.out then you can produce a binary file with your own name by using -o option while compiling C program. See an example below $cc -o hello hello.c Now you will get a binary with name hello. Execute this program at Unix prompt but before executing / running this program make sure that it has execute permissionset. If youdon't know what is execute permissionthen just follow these two steps $chmod 755 hello $./hello This will produce following result Hello, World C ongratulations!! youhave writtenyour first programin "C". Now believe me its not difficult to learn "C".