NMCP Prac01
NMCP Prac01
C++
06/04/22 1
What you should remember
You need the computer to help you compute.
You may also need its help to decide.
You need it to do these jobs repeatedly.
But after all, it is just a machine.
It does not understand anything beyond 0 and 1!
So you must learn some special code language.
Make it easy for the computer to understand too.
06/04/22 2
But for that you require an Interface
An interface is a bridge between man and machine.
An interface provides all the afore-said facilities.
It takes the help of two other utilities mainly :
The Operating System (OS)
And the Compiler or Language Translator
These are written in some code language or other.
They are all highly complex, but not beyond you!
06/04/22 3
So, you may be having a setup like this !
06/04/22 4
Which produces an output like this !
06/04/22 5
Or your setup may look like this !
06/04/22 6
What may we learn then?
How to write code in C
using special syntax (grammar of the language)
to accept (input), compute (values), & display (output)
and take decisions (if required, else not)
and setup a loop (for repeat actions)
Next transfer the code to the machine
by editing and then saving in a text file (ending in .c)
Then translate the program code to binary
to produce code computer understands (compilation)
And execute binary code to generate output
06/04/22 7
Brief Instruction : Linux/Unix user
You may have to create / obtain :
An user-id & password in order to log into the system
You may create your own directory & move into it
mkdir directoryName & cd directoryName
Next edit your C program file using gedit / vi
vi file (<file> is your source code ending in .c)
Then compile your program code to binary
cc file [- o <file1> ] (last part optional)
Execute binary code from terminal prompt
./a.out ( or ./file1 if you used the optional part)
06/04/22 8
Let’s take a
break
And investigate!
06/04/22 9
Happy Coding Then !
06/04/22 10
Problem 1 :
a) Fibonacci Series (1st 5 elements) : 0, 1, 1, 2, 3…
b)Develop a flowchart to express the logic for displaying
the first ten numbers in the Fibonacci series.
c)Represent the logic in the form of an algorithm which
accepts the count of numbers as input, and produces the
series as output.
d)Finally write the C-code for the problem and execute it.
06/04/22 11
Problem 2 :
a)If a natural number is a square number, then it has to be
the sum of Successive Odd Numbers starting from 1.
b)Develop a flowchart to express the logic for displaying
the first ten numbers in the series of such square nos.
c)Represent the logic in the form of an algorithm which
accepts the count of such numbers as input, and displays
each such square numbers along with its constituents.
d)Finally write the C-code for the problem and execute it.
06/04/22 12
Problem 3:
a)If the sum of cubes of each digit of a number is equal to
the number itself, then the number is called an Armstrong
number.
For example, 153 = ( 13 ) + ( 53) + ( 33).
b)Develop a flowchart to express the logic for displaying all
such numbers between 1 and 500.
c)Represent the logic in the form of an algorithm which
accepts the limit, and displays each such number.
d)Finally write the C-code for the problem and execute it.