PROGRAMMING FOR PROBLEM SOLVING LAB MANUAL (3)
PROGRAMMING FOR PROBLEM SOLVING LAB MANUAL (3)
1. Write a simple program that prints the results of all the operators
available in C (including pre/ post increment, bitwise and/or/not, etc.).
Read required operand values from standard input.
printf("a+b=%d\n", a+b);
printf("a-b=%d\n", a-b);
printf("a*b=%d\n", a*b);
printf("a/b=%d\n", a/b);
printf("a%%b=%d\n", a%b);
printf("++a=%d\n",++a);
printf("--b=%d\n",--b);
printf("a++=%d\n",a++);
printf("b--=%d\n",b--);
printf("a>b=%d\n",a>b);
printf("a<b=%d\n",a<b);
printf("a>=b=%d\n",a>=b);
printf("a<=b=%d\n",a<=b);
printf("a!=b=%d\n",a!=b);
printf("(a>b)&&(b<a)=%d\n",(a>b)&&(b<a));
printf("(a<b)||(b<a)=%d\n",(a<b)||(b<a));
printf("!(a!=b)=%d\n",!(a!=b));
printf("!(a==b)=%d\n",!(a==b));
printf("a&b=%d\n",a&b);
printf("a|b=%d\n",a|b);
printf("a^b=%d\n",a^b);
PROGRAMMING FOR PROBLEM SOLVING LAB MANUAL
printf("a>>2=%d\n",a>>2);
printf("b<<3=%d\n",b<<3);
}
OUTPUT:
Enter two values:9 4
a+b=13
a-b=5
a*b=36
a/b=2
a%b=1
++a=10
--b=3
a++=10
b--=3
a+=5 value is: 16
a-=2 value is: 14
a*=3 value is: 42
b/=2 value is: 1
b%=4 value is:1
a>b=1
a<b=0
a>=b=1
a<=b=0
a!=b=1
(a>b)&&(b<a)=1
(a<b)||(b<a)=1
!(a!=b)=0
!(a==b)=1
a&b=0
a|b=43
a^b=43
a>>2=10
b<<3=8
2. Write a simple program that converts one given data type to another using
auto conversion and casting. Take the values from standardinput.
#include<stdio.h>
int main( )
{
int x, sum;
char y;
float z;
printf("Enter a character:");
scanf("%c",&y);
printf(“Enter a number:”);
scanf(“%d”, &x);
OUTPUT:
Enter a character: b
Enter a number: 10
x=108, z=109.500000
sum=110
3. Write a program to find the max and min from the three numbers.
#include<stdio.h>
int main( )
{
int a,b,c;
printf("Enter 3 numbers");
scanf("%d %d %d", &a, &b, &c);
OUTPUT:
Enter 3 numbers
11
22
33
Maximum number = 33
Minimum number = 11
#include<stdio.h>
#include<math.h>
int main( )
{
float p,q,r,SI,CI;
int n;
printf("Enter the value of Principal p = ");
scanf("%f",&p);
printf("Enter Rate of Interest r = ");
scanf("%f ",&r);
printf("Enter Time Period in years n = ");
scanf("%d",&n);
SI = p*n*r/100;
printf("Simple Interest SI=%f \n",SI);
q = 1+r/100;
CI = p*pow(q, n) - p;
printf("Compound Interest CI=%f \n",CI);
return 0;
}
COMPILATION & EXECUTION:
$gcc interest.c -lm
$./a.out
OUTPUT:
#include<stdio.h>
int main( )
{
float marks;
printf("Enter percentage of marks:\n");
scanf("%f", &marks);
if(marks<40)
printf("Failed\n");
else if( marks >= 40 && marks < 60 )
printf("Second class\n");
else if( marks >= 60 && marks < 70 )
printf("First class\n");
else
printf("Distinction\n");
OUTPUT:
#include <stdio.h>
int main( )
{
int n, rows, i;
printf("Enter which multiplication table to print?\n ");
scanf("%d", &n);
printf(“Enter number of rows in the multiplication table\n “);
scanf(“%d”, &rows);
for(i =1; i <= rows; ++i)
printf("%d * %d = %d \n", n, i, n*i);
return 0;
}
OUTPUT:
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
#include<stdio.h>
#include<stdlib.h>
int main( )
int n, r, i=1,bin=0;
scanf("%d", &n) ;
exit(1);
while (n!=0) {
r = n % 2;
n /= 2;
bin += r * i;
i *= 10;
printf("%d”,bin);
return 0;
OUTPUT:
/* program to calculate the time taken by the ball dropped from the
topof the building */
#include<stdio.h>
#include<math.h>
int main( )
{
int s, i=1;
double t, a=9.8;
for(i = 1; i <= 10; i++)
}
OUTPUT:
Time taken by the ball to reach 1 floor = 0.782461
Time taken by the ball to reach 2 floor = 1.106567
Time taken by the ball to reach 3 floor = 1.355262
Time taken by the ball to reach 4 floor = 1.564922
Time taken by the ball to reach 5 floor = 1.749636
Time taken by the ball to reach 6 floor = 1.916630
Time taken by the ball to reach 7 floor = 2.070197
Time taken by the ball to reach 8 floor = 2.213133
Time taken by the ball to reach 9 floor = 2.347382
Time taken by the ball to reach 10 floor = 2.474358
9. Write a C program, which takes two integer operands and one operator
from the user, performs the operation and then prints the result.
(Consider the operators +,-,*, /, % and use Switch Statement).
case '-' : c = a - b;
printf("Difference = %d", c);
break;
case '*' : c = a * b;
printf("Product = %d", c);
break;
case '/' : c = a / b;
printf("Quotient = %d", c);
break;
case '%' : c = a % b;
printf("Remainder = %d", c);
break;
#include <stdio.h>
int main( )
{
int n, i, count = 0;
printf("Enter a number\n ");
scanf("%d", &n);
for(i = 1; i <= n; i++)
if (n % i = = 0)
count++;
if(count = = 2)
printf(“The given number %d is a prime number”, n);
else
printf(“The given number %d is not a prime number”, n);
return 0;
}
OUTPUT:
Enter a number
24
Enter a number
59
#include<stdio.h>
int main ( )
{
int temp,n,rem=0,sum=0,rev=0;
printf("Enter a positive integer\n");
scanf("%d",&n);
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+rem;
rev=(rev*10)+rem;
n=n/10;
}
if(temp==rev)
printf("Given number is a palindrome\n");
else
printf("Given number is not a palindrome\n");
OUTPUT:
printf("%d %d",f1,f2);
for(i=3; i<=terms; i++)
{
f3 = f1+ f2;
printf(" %d", f3);
f1=f2;
f2=f3;
}
return 0;
}
OUTPUT:
Enter number of terms in the fibonacci series:
6
Fibonacci series is
0 1 1 2 3 5
13. Write a C program to generate all the prime numbers between 1 and
n, where n is a value supplied by the user.
#include<stdio.h>
int main( )
{
int n, i, j, count;
printf("Enter n value:\n");
scanf("%d", &n);
printf("The prime numbers between 1 to %d are\n",n);
if(count == 2)
printf("%d\t", i);
}
return 0;
}
OUTPUT:
Enter n value:
10
The prime numbers between 1 to 10 are
2 3 5 7
#include<stdio.h>
#include<math.h>
int main( )
{
int a, b, c, d;
double root1=0.0, root2=0.0;
d = (b * b) - (4 * a * c);
if(d > 0)
{
printf("Roots are real and distinct \n");
root1 = (-b + sqrt(d)) / (2.0 * a);
root2 = (-b - sqrt(d) )/ (2.0 * a);
printf("Root1 = %lf \n”, root1);
printf(“Root2 = %lf\n", root2);
}
else if (d == 0)
{
printf("Roots are real and equal\n");
root1 = root2 = -b / (2.0 * a);
return 0;
}
OUTPUT:
return 0;
}
OUTPUT:
#include <stdio.h>
#include <math.h>
int main( )
{
int n, x, i;
scanf("%d", &n);
printf("Enter x value\n");
scanf("%d", &x);
return 0;
OUTPUT:
OUTPUT:
Enter how many elements in the array? 5
Enter 5 elements
25784
Maximum value = 8
Minimum value = 2
Average value = 13.000000
18. Write a functions to compute mean, variance, Standard Deviation
of n elements in single dimension array.
#include<stdio.h>
#include<math.h>
double std_dev(int a[ ], int n);
double variance(int a[ ], int n);
float mean(int [ ], int n);
int main( )
{
double s;
int a[50], n, i;
printf("enter how many elements:");
scanf("%d", &n);
printf("enter %d elements: ", n);
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
s=std_dev(a,n);
printf("\nstandard deviation=%f\n",s);
return 0;
}
double std_dev(int a[ ], int n)
{
double sd,v;
v=variance(a,n);
sd=sqrt(v);
return(sd);
}
double variance(int a[ ], int n)
{
int i;
float m,sum=0.0,v;
m=mean(a,n);
for(i=0;i<n;i++)
sum=sum+(m-a[i])*(m-a[i]);
v=sum/n;
printf("variance=%f\n",v);
return(v);
}
float mean(int a[ ], int n)
{
float sum=0.0,m;
int i;
for(i=0;i<n;i++)
sum=sum+a[i];
m=sum/n;
printf("\nmean=%f\n",m);
return(m);
}
OUTPUT: enter how many elements: 3
enter 3 elements: 2 6 9
mean=5.666667
variance=8.222222
standard deviation=2.867442
19. Write a C program that uses functions to perform Addition of Two
Matrices.
#include<stdio.h>
void input(int x[5][5],int m,int n);
void add(int x[5][5],int y[5][5],int z[5][5],int m,int n);
void display(int x[5][5],int m,int n);
int main( )
{
int a[5][5], b[5][5], c[5][5], m, n;
printf("enter how many rows and columns\n");
scanf("%d %d", &m, &n);
add(a,b,c,m,n);
printf("\nmatrix A is\n");
display(a,m,n);
printf("\nmatrix B is\n");
display(b,m,n);
return 0;
}
void input(int x[5][5], int m, int n)
{
int i, j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&x[i][j]);
}
void add(int x[5][5], int y[5][5], int z[5][5], int m, int n)
{
int i, j;
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
z[i][j] = x[i][j] + y[i][j];
}
void display(int x[5][5], int m, int n)
{
int i, j;
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
printf("%4d", x[i][j]);
printf("\n");
}
}
OUTPUT:
enter how many rows and columns
2 2
enter 4 elements of first matrix
1 111
enter 4 elements of second matrix
2 222
matrix A is
1 1
1 1
matrix B is
2 2
2 2
resultant matrix C is
3 3
3 3
int main()
{
int a[5][5], b[5][5], c[5][5] = {0}, r1, c1, r2, c2;
printf("enter first matrix rows and columns\n");
scanf("%d %d", &r1, &c1);
input(a, r1, c1);
printf("\nmatrix A is\n");
display(a, r1, c1);
printf("\nmatrix B is\n");
display(b, r2, c2);
return 0;
}
void input(int x[5][5], int rows, int cols)
{
int i, j;
printf("enter %d elements:", rows*cols);
for(i = 0; i < rows; i++)
for(j = 0; j < cols; j++)
scanf("%d", &x[i][j]);
}
void multiply(int x[5][5], int y[5][5], int z[5][5], int r1, int c1, int r2, int c2)
{
int i, j, k;
if(c1 != r2)
{
printf("matrix multiplication is not possible\n");
exit(1);
}
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
for(k=0;k<r2;k++)
z[i][j] += x[i][k]*y[k][j];
}
printf("\n");
}
}
OUTPUT1:
enter first matrix rows and columns
23
enter 6 elements
111111
enter second matrix rows and columns
32
enter 6 elements
222222
matrix A is
1 1 1
1 1 1
matrix B is
2 2
2 2
2 2
product matrix C is
6 6
6 6
OUTPUT2:
// input matrix A
printf("enter matrix of order %d by %d\n", rows, cols);
for(i = 0; i < rows; i++)
for(j = 0; j < cols; j++)
scanf("%d", &a[i][j]);
OUTPUT:
enter rows and columns for matrix
23
enter matrix of order 2 by 3
123
456
printf("Enter a number\n");
scanf("%d", &n);
f1 = recfactorial(n);
printf("The factorial of %d using recursion is %ld \n", n, f1);
f2 = nonrecfactorial(n);
printf("The factorial of %d using non-recursion is %ld ", n, f2);
return 0;
}
int recfactorial(int x)
{
if(x == 0 || x==1)
return(1);
return( x * recfactorial(x - 1));
}
int nonrecfactorial(int x)
{
int i;
long f = 1;
for(i = 1;i <= x; i++)
{
f = f * i;
}
return(f);
}
OUTPUT:
Enter a number
5
The factorial of 5 using recursion is 120
The factorial of 5 using non-recursion is 120
c = recgcd(a, b);
printf("The gcd of %d and %d using recursion is %d\n", a,b, c);
d = nonrecgcd(a, b);
printf("The gcd of two numbers using non-recursion is %d", d);
return 0;
}
OUTPUT:
Enter two numbers
8 20
The gcd of 8 and 20 using recursion is 4
The gcd of 8 and 20 using non-recursion is 4
24. Write a C program to find x^n.
OUTPUT:
Enter the base, x
2
Enter the power, n
3
2 to the power of 3 is: 8
25. Write a program for reading elements using pointer into array and
display the values using array.
#include<stdio.h>
int main( )
{
int a[50],*p, i, n;
p = a;
printf("Enter the size of array\n");
scanf("%d", &n);
return 0;
}
OUTPUT:
Enter the size of array
5
Enter 5 elements of array
2 34 56
#include<stdio.h>
#define MAX 30
int main( )
{
int n, i, a[MAX];
int *ptr;
ptr = &a[0];
printf("\nEnter the size of array \n ");
scanf("%d", &n);
return 0;
OUTPUT:
Enter the size of array
5
Enter 5 integers into array
11 22 33 44 55
#include <stdio.h>
#include <malloc.h>
int main( )
{
int i, n, sum = 0;
int a[20], *p;
printf("Enter the size of array \n");
scanf("%d", &n);
return 0;
}
OUTPUT:
Enter the size of array
5
Enter 5 elements
1 2 3 4 5
Sum of all elements in array = 15
28. Write a C program to display the contents of a file to standard
output device.
#include<stdio.h>
int main( )
{
FILE *fp1;
char c;
fp1 = fopen("abc.txt", "w");
fclose(fp1);
fp1 = fopen("abc.txt","r");
fclose(fp1);
return 0;
}
OUTPUT:
enter the text
hello
welcome
^d
The data from file is
hello
welcome
29. Write a C program which copies one file to another, replacing all
lowercase characters with their uppercase equivalents.
#include<stdio.h>
int main( )
{
FILE *fp1, *fp2;
char *fn1, *fn2, ch;
fp1=fopen("abc.txt","r");
fp2=fopen("file.txt","w");
return 0;
}
0UTPUT:
File successfully copied
$cat file.txt
PPS LAB
PROGRAMMING
30. Write a C program to count the number of times a character occurs
in a text file. The file name and the character are supplied as command
line arguments.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[])
{
FILE *fp1;
char ch;
int count=0;
OUTPUT:
$ ./a.out abc.txt e
The character being written was e and it occurred 3 times
rewind(fp1);
fseek(fp1,pos,SEEK_SET);
putw(k,fp1);
fclose(fp1);
fclose(fp1);
return 0;
}
OUTPUT:
$ ./a.out num.txt 1 2 3 4 5 6 7 8 9 10
Enter an index between 1 to 10: 4
Enter new value:8
1 2 3 8 5 6 7 8 9 10
32. Write a C program to merge two files into a third file (i.e., the
contents of the firs t file followed by those of the second are put in the
third file).
#include<stdio.h>
int main(int argc, char *argv[])
{
FILE *fp1, *fp2, *fp3;
int i, ch;
fp1 = fopen(argv[1], "r");
fp2 = fopen(argv[2], "r");
fp3 = fopen(argv[3], "a");
while((ch = getc(fp1)) != EOF)
putc(ch, fp3);
fclose(fp1);
fclose(fp3);
}
OUTPUT:
$ ./a.out abc.txt abc.txt third.txt
The contents of merged file
hello
welcome
hello
welcome
OUTPUT:
Enter the roman number
XIV
decimal equivalent is 14
34. Write a C program that converts a number ranging from 1 to 50 to
Roman equivalent.
/* C Program to Convert Numbers to Roman Numerals */
#include <stdio.h>
void predigit(char num1, char num2);
void postdigit(char c, int n);
char romanval[1000];
int i = 0;
int main()
{
int j;
int number;
printf("Enter the number: ");
scanf("%d", &number);
if (number <= 0)
{
printf("Invalid number");
return 0;
}
while (number != 0)
{
if (number >= 1000)
{
postdigit('M', number / 1000);
number = number - (number / 1000) * 1000;
}
else if (number >= 500)
{
if (number < (500 + 4 * 100))
{
postdigit('D', number / 500);
number = number - (number / 500) * 500;
}
else
{
predigit('C','M');
number = number - (1000-100);
}
}
else if (number >= 100)
{
if (number < (100 + 3 * 100))
{
postdigit('C', number / 100);
number = number - (number / 100) * 100;
}
else
{
predigit('L', 'D');
number = number - (500 - 100);
}
}
else if (number >= 50 )
{
if (number < (50 + 4 * 10))
{
postdigit('L', number / 50);
number = number - (number / 50) * 50;
}
else
{
predigit('X','C');
number = number - (100-10);
}
}
else if (number >= 10)
{
if (number < (10 + 3 * 10))
{
postdigit('X', number / 10);
number = number - (number / 10) * 10;
}
else
{
predigit('X','L');
number = number - (50 - 10);
}
}
else if (number >= 5)
{
if (number < (5 + 4 * 1))
{
postdigit('V', number / 5);
number = number - (number / 5) * 5;
}
else
{
predigit('I', 'X');
number = number - (10 - 1);
}
}
else if (number >= 1)
{
if (number < 4)
{
postdigit('I', number / 1);
number = number - (number / 1) * 1;
}
else
{
predigit('I', 'V');
number = number - (5 - 1);
}
}
}
printf("Roman number is: ");
for(j = 0; j < i; j++)
printf("%c", romanval[j]);
return 0;
}
void predigit(char num1, char num2)
{
romanval[i++] = num1;
romanval[i++] = num2;
}
void postdigit(char c, int n)
{ int j;
for (j = 0; j < n; j++)
romanval[i++] = c;
}
OUTPUT:
Enter the number: 500
Roman number is be: D
35. Write a C program that uses functions to insert a sub-string into a
given main string from a given position.
#include<stdio.h>
#include<string.h>
int main( )
{
char str1[20], str2[20];
int l1, l2, n, i;
puts("Enter the main string \n");
gets(str1);
l1 = strlen(str1);
l2 = strlen(str2);
str2[l2 + 1] = '\0';
printf("After inserting, the string is: %s", str1);
return 0;
}
OUTPUT:
Enter the main string
pps
Enter the sub string
lab
Enter the position where the sub string is to be inserted
3
After inserting, the string is: ppslab
36. Write a C program that uses functions to delete n Characters from a
given position in a given string.
#include<stdio.h>
#include<string.h>
int main( )
{
char str[20];
int i, n, l, pos;
puts("Enter the string\n");
gets(str);
l = strlen(str);
for(i = pos + n; i < l; i++)
str[i - n] = str[i];
str[i - n] = '\0';
return 0;
}
OUTPUT:
Enter the string
programerror
#include <stdio.h>
#include <string.h>
int main( )
{
char str[20];
int i, l, f = 0;
l = strlen(str);
for(i = 0; i <= l - 1; i++)
{
if(str[i] == str[l - 1 - i])
f = f + 1;
}
if(f == l)
printf("The string is palindrome");
else
printf("The string is not a palindrome");
return 0;
}
OUTPUT:
Enter any string
madam
The string is palindrome
#include<stdio.h>
#include<string.h>
int main( )
{
char s[30], t[20];
char *found;
if(found)
printf("Second String is found in the First String at %d position.\n",
found - s);
else
printf("-1");
return 0;
}
OUTPUT:
#include <stdio.h>
int main( )
{
char ch;
unsigned long linecount, wordcount, charcount;
int u;
linecount=0;
wordcount=0;
charcount=0;
if(charcount>0)
{
++wordcount;
++linecount;
}
return 0;
}
OUTPUT:
Enter any string
hai everyone
this is pps lab ^d
Number of characters=27
Number of words=6
Number of lines=2
40. Write a menu driven C program that allows a user to enter 5
numbers and then choose between finding the smallest, largest, sum,
or average. The menu and all the choices are to be functions. Use a
switch statement to determine what action to take. Display an error
message if an invalid choice is entered.
#include <stdio.h>
#include <stdlib.h>
int option;
int smallest(int u, int w, int x, int y, int z);
int largest(int u, int w, int x, int y, int z);
int sum(int u, int w, int x, int y, int z);
int avg(int u, int w, int x, int y, int z);
int main(void)
{
OUTPUT:
***********************
MENU
***********************
* 1. SMALLEST *
* 2. LARGEST *
* 3. SUM *
* 4. AVERAGE *
**********************
Please type your choice
2
Please enter 5 integers
23 45 67 89 08
largest number =89
printf("\n");
}
return 0;
}
OUTPUT:
Enter how many rows?
3
1
12
123
return 0;
}
OUTPUT:
Enter how many rows?
3
*
**
***
1
23
456
#include<stdio.h>
int main( )
{
int i, j, h, n, c=1;
printf(“Enter how many rows?\n”);
scanf(“%d”, &n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("%4d",c);
c++;
}
printf("\n");
}
return 0;
}
OUTPUT:
Enter how many rows?
3
1
23
456
1
22
333
4444
#include<stdio.h>
int main( )
{
int i, j, n;
printf(“Enter how many rows?\n”);
scanf(“%d”, &n);
printf("\n");
}
return 0;
}
OUTPUT:
Enter how many rows?
3
1
2 2
3 3 3
4 4 4 4
*
**
***
**
*
#include<stdio.h>
int main( )
{
int i,j,n,columns;
columns=1;
printf("Enter the number of columns\n");
scanf("%d", &n);
for(i=1;i < n*2; i++)
{
for(j=1; j <= columns; j++)
printf(" * ");
if(i < n)
columns++;
else
columns--;
printf("\n");
}
return 0;
}
OUTPUT:
Enter the number of columns
3
*
**
***
**
*
Sorting and Searching:
46. Write a C program that uses non recursive function to search for a
Key value in a given list of integers using linear search method.
#include<stdio.h>
int main( )
{
int i, a[20], n, key, flag = 0;
printf("Enter the size of an array \n");
scanf("%d", &n);
if(flag == 1)
printf("The key element is found at location %d", i + 1);
else
printf("The key element is not found in the array");
}
OUTPUT:
Enter the size of an array
5
Enter the array elements
1 3 6 2 4
Enter the key element
6
The key element is found at location 3
47. Write a C program that uses non recursive function to search for a
Key value in a given sorted list of integers using binary search
method.
#include<stdio.h>
void main()
{
int a[20], i, n, key, low, high, mid;
#include<stdio.h>
int main( )
{
int n, a[20], temp, i, j;
printf("Enter the size of the array\n");
scanf("%d", &n);
printf("Enter the array elements\n");
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
for(i = 0; i < n - 1; i++)
for(j = 0; j < n - 1; j++)
if(a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
Output:
Enter the size of the array
5
Enter the array elements
1 8 3 6 2
The sorted array is
1 2 3 6 8
49. Write a C program that sorts the given array of integers using
selection sort in descending order.
#include<stdio.h>
int main( )
{
int n, a[20], max, temp, i, j;
printf("Enter the size of the array\n");
scanf("%d", &n);
#include<stdio.h>
int main( )
{
int i, j, count, temp, number[25];
printf("How many numbers u are going to enter?: ");
scanf("%d",&count);
return 0;
}
OUTPUT:
How many numbers u are going to enter?: 4
Enter 4 elements:
2 6 8 1
The sorted array is
1 2 6 8
51. Write a C program that sorts a given array of names.
/* Program demonstrating sorting array of names */
#include <stdio.h>
#include <string.h>
int main()
{
int i, j, num;
char name[20][10], t_name[15][10], temp[20];
printf("Please enter how many number of names to be sorted\n");
scanf("%d", &num);
}
OUTPUT:
Please enter how many number of names to be sorted
5
Please enter 5 names one by one
Raj kiran sravan vijay murali
Names before sorting in alphabetical order
Raj
kiran
sravan
vijay
murali