Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Expt. No.

Date:

10.PRIME NUMBERS BETWEEN TWO INTERVALS USING FUNCTION

AIM

ALGORITHM

11
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built-in function for IO
int checkPrimeNumber(int n); // function declaration
int main()
{
int n1, n2, i, flag;
printf("\n\t\tPRIME NUMBERS BETWEEN TWO INTERVALS USING FUNCTION ");
printf("\n\t\t************************************************************");
printf("\nEnter two positive integers:\n ");
scanf("%d %d", &n1, &n2);
printf("\nPrime numbers between %d and %d are: ", n1, n2);
for (i = n1 + 1; i < n2; i++)
{
flag = checkPrimeNumber(i); // function call
if (flag == 1)
{
printf("%d ", i);
}
}
return 0;
}
int checkPrimeNumber(int n) // function definition
{
int j, flag = 1;
for (j = 2; j <= n / 2; ++j)
{
if (n % j == 0)
{
flag = 0;
break;
}
}
return flag;
}

12
SAMPLE INPUT/OUTPUT

RESULT

13
Expt. No. Date:

11.REVERSING A STRING USING RECURSION

AIM

ALGORITHM

14
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built
built-in function for IO
void reverseSentence(); // function declaration
int main()
{
char str;
printf("\n\t\t\tREVERSING
tREVERSING A STRING USING RECURSION");
printf("\n\t\t\t**********************************");
t**********************************");
printf("\nEnter a string: ");
scanf("%s",str);
printf("Thee reversed string is:");
reverseSentence(); // function call
return 0;
}

void reverseSentence() // function definition


{
char c;
scanf("%c", &c);
if (c != '\n')
{
reverseSentence();)// function is called by itself
printf("%c", c);
}}
SAMPLE INPUT/OUTPUT

RESULT

15
Expt. No. Date:

12.LARGEST ELEMENT OF AN ARRAY USING FUNCTION

AIM

ALGORITHM

16
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built-in function for IO
int largest(int[],int); // function declaration
int main()
{
int arr[50],i,n;
printf("\n\t\t\tLARGEST ELEMENT OF AN ARRAY USING FUNCTION");
printf("\n\t\t\t*****************************************");
printf("\nEnter the size of the array:");
scanf("%d",&n);
printf("\n Enter the %d elements of the array\n",n);
for(i=0;i<n;i++)
{
printf("Enter element %d:",i+1);
scanf("%d",&arr[i]);
}
printf("\n The largest element of the array is %d",largest(arr,n)) ; // function call
return 0;
}
int largest(int a[],int n) // function definition
{
int large=a[0];
for(int i=1;i<n;i++)
if(large<a[i])
large=a[i];
return(large);
}

17
SAMPLE INPUT/OUTPUT

RESULT

18
Expt. No. Date:

13. CONCATENATE TWO STRINGS WITHOUT STRCAT() FUNCTION

AIM

ALGORITHM

19
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built
built-in function for IO
int main()
{
char s1[50], s2[50];
int length, j;
printf("\n\t\t\tCONCATENATE
tCONCATENATE TWO STRINGS WITHOUT USING STRCAT() ");
printf("\n\t\t\t*******************
t******************************************************
********");
printf("\n Enter string1 : ");
fgets(s1,50,stdin);
printf("\n Enter string2 : ");
fgets(s2,50,stdin);
length = 0;
while (s1[length] != '\0' 0' &&s1[length]!='
&&s1[length]!='\n')
{
++length;
}
for (j = 0; s2[j] != '\0';
0'; ++j, ++length)
{
s1[length] = s2[j];
}
s1[length] = '\0';
printf("After concatenation: ");
puts(s1);
getch();
}

SAMPLE INPUT/OUTPUT

RESULT

20

You might also like