0% found this document useful (0 votes)
46 views13 pages

NMCP Prac01

Here are the solutions to the 3 problems in C: 06/04/22 13 #include <stdio.h> int main() { // Problem 1 int n1 = 0, n2 = 1, n3, i, count = 10; printf("Fibonacci Series: "); printf("%d, %d, ",n1, n2); for(i=3;i<=count;i++){ n3 = n1 + n2; printf("%d, ",n3); n1 = n2; n2 = n3; } // Problem 2 int num, sum=0, i, j; printf

Uploaded by

Sub m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views13 pages

NMCP Prac01

Here are the solutions to the 3 problems in C: 06/04/22 13 #include <stdio.h> int main() { // Problem 1 int n1 = 0, n2 = 1, n3, i, count = 10; printf("Fibonacci Series: "); printf("%d, %d, ",n1, n2); for(i=3;i<=count;i++){ n3 = n1 + n2; printf("%d, ",n3); n1 = n2; n2 = n3; } // Problem 2 int num, sum=0, i, j; printf

Uploaded by

Sub m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

OS & Compiler

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy