Download - Class10 12C++ Fundamentals
-
8/2/2019 Class10 12C++ Fundamentals
1/72
FUNDAMENTALS OF C++
-
8/2/2019 Class10 12C++ Fundamentals
2/72
Objective
Become familiar with fundamental tokens anddata types
Write simple computer program in C++
Use simple Output statements
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
3/72
History of C
C is a high level language.o Evolved by Dennis Ritchie and Brain Kernighan(1978)o from two previous programming languages, BCPL
(Basic Combined Programming Language ) and Bo Used to develop UNIX system software routineso Is implemented on UNIX operating systemo Structural / Modular Programmingo Portable & have compilers for almost all architectures.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
4/72
C++
C with classes (1979) C++ (1983)o Superset of C developed by Bjarne Stroustrupat Bell Labs and provides object-oriented
capabilities named c with classes.o
Object-oriented design is very powerful 10 to 100 fold increase in productivity
o Dominant language in industry and academia.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
5/72
Simple C++ program
// Display This is my first C++ program// Single line comment#include // preprocessor directivevoid main( ) // Entry point for program execution{ // block of statements: Begin
clrscr( ); //Each Statement ends with ;cout
-
8/2/2019 Class10 12C++ Fundamentals
6/72
Simple C++ Programs..// Multi lines comment
/* Find the avg. of three marks anddisplay pass or fail */
#include void main(){cout > marks1>> marks2>> marks3;avg = (marks1+marks2+marks3)/avg;
if (avg < minimum )cout
-
8/2/2019 Class10 12C++ Fundamentals
7/72
Analogy between learning English
Language and C++ Steps in learning English Language:
oAlphabetso Words
o Sentenceo Paragraphs
Steps in learning C++o
Alphabets, Digits, Special Symbolso Constants, Variables, Keywordso Instructionso Programs
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
8/72
THE C++
CHARACTER SET, IDENTIFIERSKEYWORDS, CONSTANTS
DATA TYPES, VARIABLES
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
9/72
1/23/2011 10:12:26 PM Dept of CSE
Consists of letters, digits, special characters, whitespaces.(i) Letters a, b, c,..z OrA, B, C,.Z(ii) Digits 0, 1, 2,9
(iii) Special characters ;, ?, >,
-
8/2/2019 Class10 12C++ Fundamentals
10/72
1/23/2011 10:12:26 PM Dept of CSE
C++ Tokens
Tokens
Keywords Identifiers Operators Strings constantsSpecial
Symbols
Keywordswords that are basically sequence of charactersdefined by a computer language that have one or more fixedmeanings. They are also called as reserve words. Key wordscannot be changed. Eg. int, float, do-while, if, else,..
-
8/2/2019 Class10 12C++ Fundamentals
11/72
Keywords Each keyword has a predefined purpose in the language. Do not use keywords as variable and constant names!! Some of the C/C++ keywords are
auto, bool, break, case, catch, class, char, const, continue, do,default, delete, double, else, extern, enum, false, float, for, friend,goto, if, int, inline, long, namespace, new, operator, private, protected,public, register, return, short, static, struct, sizeof, switch, template,this, throw, try, typedef, true, unsigned, virtual, void, volatile, while
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
12/72
1/23/2011 10:12:26 PM Dept of CSE
Identifiers allow us to name data and other objects in
the program.Each piece of data is stored at unique address instead ofusing addresses, names are usedExample: user defined names likeamount, avg,
Operators +, -, *, %, /, Strings ManipalConstants -15, 10Special Symbols { } (,
C++ Tokens
-
8/2/2019 Class10 12C++ Fundamentals
13/72
Identifiers
An identifier is a name for a variable, constant, function, etc.
It consists ofa letterfollowed by any sequence of letters,digits, and underscores.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
14/72
A valid identifier is a sequence of one or more letters,digits or underscore character (_).
Neither spaces nor punctuation marks or symbols can bepart of an identifier
Only letters, digits and underline characters are valid variable identifiers always have to begin with a letter
They can also begin with an underscore character (_ ),but this is usually reserved for compiler specific keywords
or external identifiers.
1/23/2011 10:12:26 PM Dept of CSE
Identifiers rules
-
8/2/2019 Class10 12C++ Fundamentals
15/72
They can not begin with a digit.
The C/C++ is a "case sensitive" language.
An identifier written in capital letters is not equivalent toanother one with the same name but written in small
letters.
The RESULT variable is not the same as the resultvariable or the Result variable
They cannot match any keyword of the C++ language oryour compiler's specific ones since they could beconfused with these.
1/23/2011 10:12:26 PM Dept of CSE
Identifiers rules
-
8/2/2019 Class10 12C++ Fundamentals
16/72
Examples of valid identifiers: First_name, age, y2000,y2k
Examples of invalid identifiers: 2000y Identifiers cannot have special characters in them. For
example: X=Y, J-20, ~Ricky,*Michael are invalididentifiers.
Identifiers are case-sensitive.For example: Hello, hello, WHOAMI, WhoAmI, whoamiare unique identifiers.
1/23/2011 10:12:26 PM Dept of CSE
Identifiers
-
8/2/2019 Class10 12C++ Fundamentals
17/72
1/23/2011 10:12:26 PM Dept of CSE
A value that IS NOT going to be changed during theexecution of our program;
Constant are specific values that are used in arithmeticexpressions or assigned to variables, e.g. 2, 5, -10, 2.e+6,
3.14159, and so forth; Sometimes a constant represents truly a constant value in
nature such as:
Pi 3.14159
speed of light 2.99792+E8 meters/sec
Constants
-
8/2/2019 Class10 12C++ Fundamentals
18/72
1/23/2011 10:12:26 PM Dept of CSE
Constants
-
8/2/2019 Class10 12C++ Fundamentals
19/72
Integer ConstantsRefers to a sequence of digits.Decimal, Octal , Hexadecimal.
o Decimal: set of digits 0 to 9, preceded by
optional or + signo Octal: digits 0 to 7 with a leading 0o Hexadecimal: digits 0 to 9, char A to F
preceded by 0xE.g.: 143, -564, 0346, 0x34, 0x8AF
1/23/2011 10:12:26 PM Dept of CSE
Numeric Constants
-
8/2/2019 Class10 12C++ Fundamentals
20/72
Used to represent numbers with fractional partE.g.; 213.45, .456,234.
Another form mantissa e exponent0.56e4, 3.12E4 , -4.6E-1
1/23/2011 10:12:26 PM Dept of CSE
Floating Point Constant
Character ConstantsSingle characterSingle character with in a pair ofsingle quote ( )
marks, having integer values known as ASCIIvalues.E.g.: d, t, 9
-
8/2/2019 Class10 12C++ Fundamentals
21/72
A sequence of characters enclosed in doublequotes ( ). Characters may be letters, numbers,special characters and blank space.E.g.: hello, 2007, T, 4+5
Backslash character constants
Used in output functionsE.g.: \n new line, \0 null char, \a, \b, \t, \
Also known as escape characters.
1/23/2011 10:12:26 PM Dept of CSE
String Constants
-
8/2/2019 Class10 12C++ Fundamentals
22/72
1/23/2011 10:12:26 PM Dept of CSE
Which helps us to associate an identifier with a constantvalue in your program;
The advantage is that you can refer to the identifier anytime you need to use the constant value instead of having
to repeat writing the value; To declare a symbolic constant you must do it as follows:
constdata typeidentifier= value;
Symbolic Constants
-
8/2/2019 Class10 12C++ Fundamentals
23/72
1/23/2011 10:12:26 PM Dept of CSE
Consider the Example below:
void main() { float area, perimeter;
float radius; const double Pi = 3.14159;
area = radius * radius * Pi; perimeter = 2 * Pi * radius; cout
-
8/2/2019 Class10 12C++ Fundamentals
24/72
A variable is a data name that may be used to store adata value. A variable may take different values at different times
during execution. Variable name chosen by the programmer in a
meaningful way. Each variable needs an identifier that distinguishes it
from the others.( rules similar to identifier)
1/23/2011 10:12:26 PM Dept of CSE
Variables
-
8/2/2019 Class10 12C++ Fundamentals
25/72
1/23/2011 10:12:26 PM Dept of CSE
C++ data Types
-
8/2/2019 Class10 12C++ Fundamentals
26/72
1/23/2011 10:12:26 PM Dept of CSE
Data types
C++ Language is rich in its data typesMainly 4 classes of data types Primary (fundamental or Built-in type) data types, User defined Data types Derived Data types
Thefundamental or Built-in data typesfall into one ofthree categories Integer type Floating-point type
Character type Empty data set.
-
8/2/2019 Class10 12C++ Fundamentals
27/72
1/23/2011 10:12:26 PM Dept of CSE
Primary (built-in or Basic)Data types
void
SIGNED TYPE UNSIGNED TYPEINT UNSIGNED INT
SHORT INT UNSIGNED SHORT INTLONG INT UNSIGNED LONG INT
SIGNED CHARCATERUNSIGNED CHARACTER
FLOATDOUBLE
LONG DOUBLE
INTEGER CHARACTER
FLOATING POINT TYPE
INTEGRAL TYPE
-
8/2/2019 Class10 12C++ Fundamentals
28/72
Integer Types
The basic integer type is into The size of an int depends on the machine and the
On PCs it is normally 16 or 32 bits
Modifierso short: typically uses less bitso long: typically uses more bitso unsignedo signed
Different types allow programmers to use resources moreefficiently.
Standard arithmetic and relational operations areavailable for these types.
1/23/2011 10:12:26 PM Dept of CSE
short intint
long int
-
8/2/2019 Class10 12C++ Fundamentals
29/72
SIZE AND RANGE OF VALUES FOR A16-BIT MACHINE (INTEGER TYPE)
1/23/2011 10:12:26 PM Dept of CSE
Type Size(bits)
Range
short
short int orsigned short int 8 -128 to 127
unsigned int 8 0 to 255
integerint or signed int 16 -32,768 to 32,767
unsigned int 16 0 to 65,535
long
long int orsigned long int 32
-2,147,483,648 to2,147,483,647
unsigned long int 32 0 to 4,294,967,295
-
8/2/2019 Class10 12C++ Fundamentals
30/72
Character Types
Character type charisrelated to the integer types Modifiers unsigned and signed can be used char 1 byte(-128 to 127) signed char 1 byte(-128 to 127) unsigned char 1 byte(0 to 255)
Characters are encoded using a scheme where aninteger represents a particular character
ASCII is the dominant encoding scheme(American Standard Code for Information Interchange ) Examples
o ' ' encoded as 32 '+' encoded as 43o 'A' encoded as 65 'Z' encoded as 90o 'a' encoded as 97 'z' encoded as 122
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
31/72
Floating-Point Types Floating-point types represent real numbers
o Integer parto Fractional part
The number 108.1517 breaks down into the followingpartso 108 - integer parto 1517 - fractional part
C provides three floating-point typeso floato doubleo long double
1/23/2011 10:12:26 PM Dept of CSE
floatdouble
long double
-
8/2/2019 Class10 12C++ Fundamentals
32/72
1/23/2011 10:12:26 PM Dept of CSE
Type Size Range
SinglePrecision float 32 bits4 bytes Numbers between3.4 E-38 and 3.4E+38
Double
Precision
double64 bits8 bytes
Numbers between 1.7E-
308 and 1.7E+308
Long DoublePrecision
long double80 bits
10 bytesNumbers between 3.4E-
4932 and1.1E+4932
SIZE AND RANGE OF VALUES FOR16-BIT MACHINE (FLOATING POINT)
-
8/2/2019 Class10 12C++ Fundamentals
33/72
void
2 uses of void areo To specify the return type of a function when it is not
returning any valueo To indicate an empty argument list to a function
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
34/72
1/23/2011 10:12:26 PM Dept of CSE
Logical or Boolean data- named after FrenchMathematician/philosopher George Booleo Consists of only two values: true and falseo Nonzero number can be used to represent trueo Zero is used to represent false
Boolean
-
8/2/2019 Class10 12C++ Fundamentals
35/72
1/23/2011 10:12:26 PM Dept of CSE
Declaration of variables In order to use a variable in C++, we must first declare it. It does two things
Tells the compiler the variable name. Specifies the type of data.
Primary Type declaration:
write the specifier of the desired data type (like int, char,float...) followed by a valid variable identifier.i.e data-type V1, V2,,Vn ;
For example:int a;float mynumber, sum;
-
8/2/2019 Class10 12C++ Fundamentals
36/72
1/23/2011 10:12:26 PM Dept of CSE
The integer data types short, longand intcan be eithersignedorunsigneddepending on the range of numbersneeded to be represented.
Signed types can represent bothpositive and negative
values, whereas unsigned types can only representpositive values (and zero).
Declaration of variables
-
8/2/2019 Class10 12C++ Fundamentals
37/72
1/23/2011 10:12:26 PM Dept of CSE
Signed and unsigned can be specified by using eitherthe specifiersignedor the specifierunsignedbeforethe type name.For example:
unsignedshort int NumberOfSisters;
signedint MyAccountBalance By default most compiler settings will assume the type to
be signed(exception is char).
Declaration of variables
-
8/2/2019 Class10 12C++ Fundamentals
38/72
1/23/2011 10:12:26 PM Dept of CSE
Short and long can be used alone as type specifiers.o
The following two variable declarations are equivalent: short Year; short int Year;
Signed and unsigned may also be used as standalone typespecifiers.o
The following two declarations are equivalent: unsigned NextYear; unsigned int NextYear;
Declaration of variables
-
8/2/2019 Class10 12C++ Fundamentals
39/72
1/23/2011 10:12:26 PM Dept of CSE
Floating point:keywords float, double, long double Character Type:
keywords char, unsigned char, signed char.
Eg:double deviation;char p, q;
Declaration of variables
-
8/2/2019 Class10 12C++ Fundamentals
40/72
Assigning values to variables
Values can be assigned using the assignment operator = o It is possible to assign at the time of declaration.
data-type varaiable-name=constant ;int final_value = 100, p = 20;char yes = m;The process of giving initial values to variables Initialization. external & static variables initialized to zero by default. Assigning values to variables after declaration
Eg: initial = 1; area = 23.89;const int class_size= 40;const tells the compiler the value of variable class_size must not modified by
the program. It can be used on the right hand side of any assignmentstatement.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
41/72
1/23/2011 10:12:26 PM Dept of CSE
Initialization of variables example
#include void main (){ int a=5;// initial value = 5int b;b=2;// initial value = 2int result;// initial value undetermineda = a + 3;result = a - b;cout
-
8/2/2019 Class10 12C++ Fundamentals
42/72
User defined Type declarations
typedefo Type definition - lets you define your own type
identifiers.
enumo Enumerated data type - a type with restricted set of
values.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
43/72
User defined Type Declaration typedef: general declaration format
typedeftypeidentifier;The type refers to an existing data type and identifier refersto the new name given to the data type.
After the declaration, we can use the identifier to declare variables.
typedefintmarks;typedeffloatunits;marks m1,m2; //m1 & m2are declared as integer variablesunits u1, u2;//u1 & u2are declared as floating point variablesThe main advantage of typedef is that we can create meaningful data type
names for increasing the readability of the program.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
44/72
User defined Type Declaration
enum data type :general declaration formatenum identifier {value1, value2,..,valuen};
The identifier is a user defined enumerated data typewhich can be used to declare variables that can have one
of the values known as enumeration constants.After this declaration as follows:enum identifier v1,v2,vn;
enumerated variables v1,v2,..,vn can only have one of the
values value1, value2,,valuen
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
45/72
User defined Type DeclarationE.g.:enumday {Mon, Tue, Wed, Thu, Fri, Sat, Sun} ;enum day week_st, week_end, Today;week_st = Mon;week_end= Sat;if(Today== Fri) cout
-
8/2/2019 Class10 12C++ Fundamentals
46/72
1/23/2011 10:12:26 PM Dept of CSE
cout>i;switch(i){
case Monday:cout
-
8/2/2019 Class10 12C++ Fundamentals
47/72
Review of Data Types
What is a data type? List the different category of data tyes? Name the types under Built-in Data types. Discuss the variations of the following:
int, char, float What is void? Why it is required? How you can declare variables? What is initialization? Why it is required? List the six different steps involved in executing a
program.
1/23/2011 10:12:26 PM Dept of CSE
T i l C++ P D l t
-
8/2/2019 Class10 12C++ Fundamentals
48/72
Typical C++ Program DevelopmentEnvironment
Phases of C++Programs:1.Edit
Preprocess Compile Link Load Execute
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
49/72
1/23/2011 10:12:26 PM Dept of CSE
1 // Program: first.cpp 2 // My first program in C++. 3 #include 4 5 // function main begins program execution 6 int main() 7 {
8 cout
-
8/2/2019 Class10 12C++ Fundamentals
50/72
// Program: first.cpp// my first program in C++
These are single line comments. All lines beginning with two slash signs (//) are
considered comments They do not have any effect on the behavior of theprogram
The programmer can use them to include shortexplanations or observations within the source code itself.
1/23/2011 10:12:26 PM Dept of CSE
Comments
-
8/2/2019 Class10 12C++ Fundamentals
51/72
#include
Lines beginning with a sign (#) are directives for thepreprocessor. They are not regular code lines. directive #include tells the preprocessor to
include the iostream standard header file.
This specific file (iostream.h) includes the declarations of thebasic standard input-output library in C++, and it is includedbecause its functionality is going to be used later.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
52/72
void main ()
The main function is the point where all C++ programs starttheir execution, independently of its location within thesource code.
it is essential that all C++ programs have a main function.
The word main is followed in the code by a pair ofparentheses (). That is because it is a function declaration.
Optionally, these parentheses may enclose a list ofparameters within them.
Right after these parentheses we can find the body of themain function enclosed in braces{ }.
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
53/72
cout
-
8/2/2019 Class10 12C++ Fundamentals
54/72
cin>>Rules
>> known as extraction orget fromoperator. It extracts the value from keyboard & assign it to the
variable on its right.
Integer read
o Ignores/skips leading white space characters (space,tab, new line)
o Begins collecting digits, stops at the first non-digitcharacter (leaving that character in the buffer)
Character reado Ignores/skips leading white space characters (space,
tab, new line)o Reads next character (any valid ASCII character)
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
55/72
cin>>Rules
String reado Ignores/skips leading white space characters (space,
tab, new line)o Collects characters and stops at the first white space
characterE.g.:cin>>a;
cin>>b>>c;
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
56/72
cout
-
8/2/2019 Class10 12C++ Fundamentals
57/72
1/23/2011 10:12:26 PM Dept of CSE
1 // Program: Second.cpp
2 // Printing a line with multiple statements.3 #include 45 // function main begins program execution6 int main()7 {
8 cout
-
8/2/2019 Class10 12C++ Fundamentals
58/72
1/23/2011 10:12:26 PM Dept of CSE
1 // Program: third.cpp
2 // Printing multiple lines with a single statement3 #include 45 // function main begins program execution6 int main()7 {8 cout
-
8/2/2019 Class10 12C++ Fundamentals
59/72
1/23/2011 10:12:26 PM Dept of CSE
1 // Program: Add.cpp2 // Addition program.3 #include 45 // function main begins program execution6 void main()
7 {8 int integer1; // first number to be input by user9 int integer2; // second number to be input by user10 int sum; // variable in which sum will be stored1112 cout > integer1; // read an integer
1415 cout > integer2; // read an integer1718 sum = integer1 + integer2; // assign result to sum1920 cout
-
8/2/2019 Class10 12C++ Fundamentals
60/72
Algorithm : read and display a no.
Step1: Read a no.
Step 2: [display it on the screen]Print the no. is =, no.
Step 4: [End of algorithm]
Stop
WAP to read and display a number
Input a no.
Print theno.
Start
Stop
1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
61/72
#include // header file for input/output#include// header file for clrscr() & getch()void main()//main function{//program body begins
clrscr();//in-built functionint a;//variable declarationcouta;// reading or input value to the variablecout
-
8/2/2019 Class10 12C++ Fundamentals
62/72
1/23/2011 10:12:26 PM Dept of CSE
To convert seconds into minutes & seconds To convert Celsius to Fahrenheit & vice versa
Write C++ Programs
[algorithm, flowchart & program]
-
8/2/2019 Class10 12C++ Fundamentals
63/72
Algorithm : conversion of secs into hr, min, secs
Step1: Read secs
Step 2: [do conversions]
hr= sec/3600sec=sec mod 3600min= sec/60sec= sec mod 60Step 3: print hours= hr, minutes= min, seconds= sec
Step 4: [End of algorithm]Stop
WAP to convert seconds into hours,minutes & seconds
hr= sec/3600min= (sec mod 3600)/60
sec= (sec mod 3600) mod 60
Input sec
Print hr, minand sec
Start
Stop
1/23/2011 10:12:26 PM Dept of CSE
P t t t d i t
-
8/2/2019 Class10 12C++ Fundamentals
64/72
#include
#includevoid main( ){int sec, hr, min;coutsec;hr= sec/3600; sec = sec % 3600;min= sec/60;sec= sec % 60;cout
-
8/2/2019 Class10 12C++ Fundamentals
65/72
Algorithm : To convert Celsius to Fahrenheit & vice versaStep1: Read celsiusStep 2: Fahrenheit =(9.0 / 5.0) * celsius + 32.0Step 3: Print temp in Fahrenheit= FahrenheitStep 4: Read FahrenheitStep 5: celsius =(Fahrenheit 32) * (5.0 / 9)Step 6: Print temp in celsius= celsiusStep 7: Stop
WAP to convert Celsius toFahrenheit & vice versa
1/23/2011 10:12:26 PM Dept of CSE
Fl h t
-
8/2/2019 Class10 12C++ Fundamentals
66/72
Flowchart
Read Celsius
Fahrenheit =(9.0 / 5.0) * celsius + 32.0
print Fahrenheit
Read Fahrenheit
celsius =(Fahrenheit 32) * (5.0 / 9)
Print Celsius
Start
Stop1/23/2011 10:12:26 PM Dept of CSE
-
8/2/2019 Class10 12C++ Fundamentals
67/72
#include#includevoid main() {float faren , cel;coutcel;faren=(9.0 / 5.0) * cel + 32.0;cout
-
8/2/2019 Class10 12C++ Fundamentals
68/72
1/23/2011 10:12:26 PM Dept of CSE
To exchange memory variable a and b To display a triangle of * on the screen Find the sum of digits of a 4-digit number
Write C++ Programs
Program to exchange memory
-
8/2/2019 Class10 12C++ Fundamentals
69/72
# include# includevoid main( ) {int a,b;couta;
cin>>b;a=a + b;b=a-b;a=a-b;cout
-
8/2/2019 Class10 12C++ Fundamentals
70/72
#include#includevoid main(){clrscr();
cout
-
8/2/2019 Class10 12C++ Fundamentals
71/72
#include#includevoid main(){clrscr();int num, digit, sum=0;coutnum;digit= num%10;sum=sum + digit;num=num/10;
digit= num%10;num=num/10;sum=sum + digit;digit= num%10;num=num/10;sum=sum + digit + num;cout
-
8/2/2019 Class10 12C++ Fundamentals
72/72
Try the Following problems
1. Write a C++ program to read the price of an item indecimal form(like 15.95) and print the output in paise(like1595 paise).
2. Write a C++ program to covert distance in mm to cm,
inch, feet (1 cm =10mm, 1inch=2.5cm, 1 feet =12 inches).