Raghu Institute of Technology
Raghu Institute of Technology
R13 Syllabus
a[0]
a[0]
i<size
5.3.1:if the condition is true then it enter into loop and small<a[i] is checked
5.3.2:if the condition is false then it comes out of loop
5.4:Display smallest element
5.5:End the smallest function and return to the main function
FLOW CHART:START
STOP
Largest( ) begin
Declare big,a[ ]
FALSE
big
a[i]
Largest ( ) - end
Smallest( ) begin
Declare small,a[ ]
Small
a[0]
FALSE
For i in steps of 1 do
where i<size
TRUE
FALSE
Small<a[i]
Small
a[i]
Smallest element
Smallest( )- end
PROGRAM
/*C Program to find largest and smallest numbers of an array using pointers*/
Program name:
/* Done By : C-Faculty
#include<stdio.h>
#include<curses.h>
void largest( );
void smallest( );
int main( )
int size,a[50];
{
printf(Enter the size of an array);
scanf(%d,&size);
printf (Enter elements into array);
for(i=0;i<size;i++)
{
scanf(%d&a[i]);
}
largest( )
smallest( )
return(0);
}
void largest ( )
{
int big , a[i];
Department of Computer Science & Engg
// wk11a.c
Dated: 15/10/2013*/
big =a[0];
for(i=1;i < size ;i++)
{
if(big < a[i])
}
}
printf(the largest elements is %d;big);
}
void smallest( )
{
int small, a[i];
small=a[0];
for(i=1; i<size;i++)
{
if( small > a[i])
{
small=a[i];
}
}
printf(smallest elements is %d;small);
}
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk11a.c lcurses
Department of Computer Science & Engg
69 98
Largest element is 98
Smallest element is 25
ORIGINAL OUTPUT:
Enter the size of an array:4
Enter the elements into the array:38 44 21 48
Largest element is 48
Smallest element is 21
--xXx--
sum(a,b,c)
step 4:-Compute
avg
x/3
p+q+r
FLOWCHART:
start
Declare x,y,avg
Call function X=sum(a,b,c)
avg=x/3
Display avg
stop
Stop
Sum-begin
Declare integer
variable d
Read p,q,r
d=p+q+r
Sum-end
PROGRAM
/* C Program for implementing call by value */
Program name:
/* Done By : C-Faculty
#include<stdio.h>
#include<curses.h>
int sum(int ,int ,int)
int main( )
{
int x,y,avg;
clear( );
x=sum (a ,b ,c);
avg=x/3;
printf(%d,avg);
return(0);
}
int sum ( p,q,r )
{
int d;
printf(enter the values);
scanf(%d%d%d, &p,&q,&r);
d=p+q+r;
return(d);
}
// wk11b.c
Dated: 15/10/2013*/
--xXx--
*p + *q
start
Call the
functionAdd(&a,&b)
Display elements
Stop
Add function
C= *p+*q
Add end
Department of Computer Science & Engg
PROGRAM
/* C Program to illustrate call by reference */
Program name:
/* Done By : C-Faculty
// wk11c.c
Dated: 15/10/2013*/
#include <stdio.h>
#include <curses.h>
void add (int *, int*);
int main ( )
{
int a, b;
clear ( );
printf (enter values);
scanf (%d%d, &a,&b);
add(&a,&b);
printf(Elements after adding are %d,c)
return(0);
}
void add( int *p, int *q )
{
int c;
c=*p+*q;
}
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Department of Computer Science & Engg