CPR Assignment Part 1
CPR Assignment Part 1
Algorithm
Step 1 : START.
Step 2: PRINT Enter the two num bers"
Step 3 : INPUT a,b.
(Page No.
Date
Step 4 X= a.
Step 5 a=b.
Step 6 : b = ,
Elowchart .
START
b=x
PRINT Q,b
STOP
(Page No.
Date
<nmod 2
Output:
three numbers : 15 |5 15
Enter
15,15,15 is l5.000
AVeroge of
Page No.
Dete
Example :
If X =4;
Then y =ttX ;
Fage No
Date
Compiler InterpreBer
A Compiler translates code An interpreter ranslates
from a higher -level prog-Code coritten in a high
Tamming language into Jevel progromming language
machine Code before theinto machine code Iine-by
pioqiam Yuns. -line as the code Yuns
Assignnent 2
Stote use of Continue stotement.
I is used 4o bring the program (ontrol t0.
Hhe beginning of the loop.
ilLhe coninue statement Skips Some lines ot
Code inside the lo0p ond onHinues coith the
next iterGtion
Write a C progrom to
numbers enBered by userfind sum of natural
#include <Stdio.h)
HInclude<
int main (0
Conio.h)
int n, L,5um =0 ;
DIintFEnter a
number :\n";
SCanf"d",&n);
for (i= 1; i(=n; +ti)
5um t =i;
Syntox
While (test condition )
Example
find the sum and produc
Write_aC pIogiam_to
digit 0f a yse entered num ber
o all the
# include <stdio.h)
#include<conio-h)
Void moin()
getchC1
Page No.
Date
ConHinue:
while do cohile
Syntax:
for (inHiallzaion est Condilon, increrment o
decrement)
Body 0f the loop ;
Expiession:
progiom to print EATC five times
Write a(_
# jnclude <Stdia.h>
#jnclude <Conio.h)
Void main)
clIscrC):
for Ci=1;i<= 5; itt)
prindfC"E TC\n")
Qutput:
EATC
ETC
ETC
E TC
ESTC
Page No.
Date
povides a
T! D)OVides moe concise ond some Himes more
RICient ay of hond ling SUch scenaios
I! elseiS used to test he descisions while a
Suitch Statement 0s used to test the yo lue of
the qiven Vaviable ggainst list of Case Valve
Exomple
Using if - else staBement
HCday of week.equals ("saBurday") I| day of week
fquals ('sunday' ))
dakatype= "Weekend;
3
else
Exomple:
numbers
Nite a progiom to disploy n noBural
enBered by useY
int n j=1;
Drintf(" Enter a number :"):
5C0nf"d" Sn):
ore :\n", n;
Orin+F C First Zd natural numbers
while Ci<=n)
print f C" Z.d"i):
itti
2
else
Case 1:
while Cn)o)
prinB f C"Zd" D:
bregk
default : printf (" Jnvolid number");
getchC):
Page No
Assignment 3. 2
Recussion :
Recursion is_ a procPS5 where Qfunction calls itself
Exoyple:
#include Kstdio.b)
int facBorial (int no):
yojd ain)
int no,ans;
pintf C"|n Enter the number"):
Scont("%d" &no):
On5 =foctcial Cno):
p1intt C"In koctoial af Yd is Zd" n0,0n5)
qet chC);
int factovial Cint no)
int fact :
i (o= 1)
Tetuyn(1):
else
foct : no facouial Cn0 -1):
1etuin(fact),
int x.yi
printf(Enter value for x ");
SCon f(Zd " &x):
printf("Ente volue fox y:):
Scanf "A",8y):
Suap( x, y
pint f ("Affei 5apping: x2d, y: 2.d\n". , y);
getch():
Pape
tNTit a
4 Etampleprogram to find factoio) of given numbey
NriBe the program to find the foctorialL OE he given
n. using the ecursion
#inctude (stdio.h
int factoriol Cint no ):
Void main )
int no. ans:
printf ("\n Enter the number
SCanf C"Zd" no):
ans = factorial (no):
printF (\n Foctorial of %d is Xd". no ans):
gekchl).
int factoiial Cint no)
Int foct :
If (no==1)
YeBurn (1);
else
fact = no factoriol (Cno-1):
Yeturn (Fact):
Output.
Enter a number 5
Factorial 0f 5 is 120
Page No.
Date
with yntax.
6 list any two librory functions
1. pintf):
Syniax
int printf (Const chayformot,...
2. Scanf(;
This funcHion is used to 1ead formatted input from
the standord output.
Syntox
int sconf Cconst chay *format, ...):