Write the functions to perform the following : 10m Dec2005
(i) To find mn where m, n > 0
#include<stdio.h>
void main()
{
long int power(int,int);
int M,N;
long int RES;
printf(“ENTER M : “);
scanf(“%d”,&M);
printf(“ENTER N : “);
scanf(“%d”,&N);
RES=power(M,N);
printf(“\nRESULT IS %ld “,RES);
getch();
}
long int power(int M,int N)
{
long int i,RESULT=1;
for(i=0;i<N;i++)
{
RESULT*=M;
}
return(RESULT);
}
CODE : –
[codesyntax lang=”c” lines=”normal”]
#include<stdio.h>
void main()
{
long int power(int,int);
int M,N;
long int RES;
printf(“ENTER M : “);
scanf(“%d”,&M);
printf(“ENTER N : “);
scanf(“%d”,&N);
RES=power(M,N);
printf(“\nRESULT IS %ld “,RES);
getch();
}
long int power(int M,int N)
{
long int i,RESULT=1;
for(i=0;i<N;i++)
{
RESULT*=M;
}
return(RESULT);
}
[/codesyntax]
SCREEN SHOTS :-
(ii) To swap two variables
# include <stdio.h>
void main()
{
int M,N;
void swapRef ( int *, int * );
clrscr();
printf(“ENTER M : “);
scanf(“%d”,&M);
printf(“ENTER N : “);
scanf(“%d”,&N);
printf (“\nBefore calling function swapRef M=%d N=%d”,M,N);
swapRef (&M,&N); /*address of arguments are passed */
printf(“\nAfter calling function swapRef M=%d N=%d”,M,N);
getch();
}
void swapRef (int *pm, int *pn)
{
int temp;
temp = *pm;
*pm = *pn;
*pn = temp;
printf (“\nWithin function swapRef *pm=%d *pn=%d”,*pm,*pn);
return;
}
CODE : –
[codesyntax lang=”c” lines=”normal”]
# include <stdio.h>
void main()
{
int M,N;
void swapRef ( int *, int * );
clrscr();
printf(“ENTER M : “);
scanf(“%d”,&M);
printf(“ENTER N : “);
scanf(“%d”,&N);
printf (“\nBefore calling function swapRef M=%d N=%d”,M,N);
swapRef (&M,&N); /*address of arguments are passed */
printf(“\nAfter calling function swapRef M=%d N=%d”,M,N);
getch();
}
void swapRef (int *pm, int *pn)
{
int temp;
temp = *pm;
*pm = *pn;
*pn = temp;
printf (“\nWithin function swapRef *pm=%d *pn=%d”,*pm,*pn);
return;
}
[/codesyntax]
SCREEN SHOTS :-
Q Write a program in ‘C’ to find and display the minimum and maximum values of an array of integers. Note : You should use “pointers” concept only 5m Dec2005
Solved program can be found on this link http://cssimplified.com/c-programming/a-c-program-with-a-function-that-returns-the-minimum-and-the-maximum-value-in-an-array-of-integers