Professional Documents
Culture Documents
Svietkanuru - TK: List of "C" Programs
Svietkanuru - TK: List of "C" Programs
Simple Programs
WAP to find the average of three numbers. (Pgm No. 1)
2.
3.
4.
WAP to print whether the given number is even or odd. (Pgm No. 4)
5.
6.
WAP to swap two numbers without using temporary variable. (Pgm No. 6)
7.
WAP to find whether the given number is prime or not. (Pgm No. 7)
8.
WAP to check whether the given number is Armstrong or not. (Pgm No. 8)
9.
WAP to check whether the given number is palindrome or not. (Pgm No. 9)
ie
sv
1.
11.
tk
10. WAP to print the Fibonacci series up to a given input number. (Pgm No. 10)
WAP to print the greatest of the three numbers. (Pgm No. 11)
an
12. WAP to verify the given alphabet is vowel or not. (using switch-case) (Pgm No. 12)
u.
ur
13. Write a menu driven program to perform addition, subtraction, multiplication, division, modulo division
14. WAP to print the ascending order of three numbers. (Pgm No. 14)
15. WAP to print y = 1 for x > 0, y = 0 for x = 0, y = -1 for x < 0 using conditional operator. (Pgm No. 15)
tk
16. WAP to illustrate the operations of increment and decrement operators. (Pgm No. 16)
Programs to illustrate Mathematical library functions and #define
17. WAP to calculate the value of (i). ax2+bx+c (ii). b2-4ac / 2a (iii). xlogx (iv). cos2x +sin2x (Pgm No. 17)
18. WAP to find the area of the triangle with (i). given sides a, b, c (ii). given height and
breadth. (Pgm
No. 18)
19. WAP to find (i). area of circle (ii). circumference of the circle. (Pgm No. 19)
20. WAP for the following series 1 1/22 + 1/32 ..1/n2 using mathematical functions.
21. WAP for the following series ex = 1 + x + x2/2! + x3/3! + .. using mathematical functions.
22. WAP for the following series sinx = x x3/3! + x5/5! x7/7!.. using mathematical functions.
Programs on Single Dimensional Arrays
23. WAP to find out the maximum & minimum element from the given array. (Pgm No.20)
24. WAP to display the position of a given number in an array. (Pgm No.21)
25. WAP to insert a number in to an array at the required position. (Pgm No.22)
26. WAP to delete a number in an array at the given position. (Pgm No.23)
27. WAP to calculate the frequency of a given number in an array. (Pgm No.24)
28. WAP to calculate the mean, variance, standard deviation for the given array elements. (Pgm No.25)
sv
ie
tk
33. WAP to print the sum of (i) all row elements (ii) all column elements in an array. (Pgm No.30)
34. WAP to evaluate the addition of two mxn and mxn matrices. (Pgm No.31)
an
35. WAP to evaluate the matrix multiplication of two mxn and nxq matrices. (Pgm No.32)
36. WAP to display the upper, lower matrix for a given array. (Pgm No.33)
Programs on Strings
ur
u.
38. i). WAP to copy one string into another string with the use of built in functions. (Pgm No.35 a)
ii). WAP to copy one string into another string without using any built in functions. (Pgm No.35 b)
tk
39. i). WAP to concatenate two strings with the use of built in functions. (Pgm No.36 a)
ii). WAP to concatenate two strings without using any built-in functions. (Pgm No.36 b)
40. i). WAP to compare two strings with the use of built in functions. (Pgm No.37 a)
ii). WAP to compare two strings without using any built in functions. (Pgm No.37 b)
41. i). WAP to find length of a string with the use of built-in functions. (Pgm No.38 a)
ii). WAP to find length of a string without using any built in functions. (Pgm No.38 b)
42. i). WAP to convert strings from lower case to upper case with the use of built-in functions. (Pgm No.39
a)
ii). WAP to convert strings from lower case to upper case without using any built in functions. (Pgm
No.39 b)
43. i). WAP to convert strings from upper case to lower case with the use of built-in functions. (Pgm No.40
a)
ii). WAP to convert strings from upper case to lower case without using any built in functions. (Pgm
No.40 b)
44. i). WAP to reverse a string with the use of built-in functions. (Pgm No.41 a)
ii). WAP to reverse a string without using any built in functions. (Pgm No.41 b)
45. i). WAP to check whether a given string is palindrome or not with the use of built-in functions. (Pgm
No.42 a)
sv
ii). WAP to check whether a given string is palindrome or not without using any built in functions. (Pgm
No.42 b)
ie
3
4
4
5
ur
Programs on Structures
47.
an
tk
WAP to create student data structure that accepts as well as to display Student Name (First
u.
Name, Last Name), Branch, Regd No, Address(D.No, Address Line 1,Street Name, District, Pin Code),
Contact Number (Land Line, Mobile 1, Mobile 2) of 15 students.
tk
48. WAP to menu driven program to perform the operations add, subtract, multiply, divide, modulo division
of two complex numbers x+iy, a+ib using functions with arguments and return values. (Pgm No.44)
49. WAP to find the sum of all elements in an array by using functions with arguments and no return values.
(Pgm No.45)
50. WAP to swap two number using call by reference concept. (Pgm No. 46)
Programs to illustrate the concept of recursion
51. WAP to calculate the factorial of a given number using recursion. (Pgm No.47)
52. WAP to calculate the Fibonacci series by using recursion. (Pgm No.48)
tk
u.
ur
an
tk
ie
sv
C Programs
Simple Programs
1.
#include<stdio.h>
main()
{
int a, b, c;
float avg;
sv
ie
#include<stdio.h>
{
float cel, fah;
ur
an
main()
tk
2.
u.
tk
3.
#include<stdio.h>
main()
{
int n, i, fact=1;
printf("\n Enter a number of your choice :");
scanf("%d",&n);
for(i = 1;i <= n; i++)
{
fact = fact * i;
}
printf("\n The factorial of the given number is %d",fact);
}
4.
#include<stdio.h>
main()
{
int num;
printf("\n Enter a number of your choice :");
sv
scanf("%d", &num);
if(num % 2 == 0)
else
ie
tk
void main()
int a,b,temp;
ur
an
#include<stdio.h>
u.
scanf("%d %d",&a,&b);
a = b;
b = t;
tk
t = a;
#include<stdio.h>
void main()
{
int a,b;
sv
#include<stdio.h>
main()
ie
int n,i,rem,count=0;
scanf("%d",&n);
if(n==1)
an
tk
for(i=2;i<=n;i++)
{
if(rem==0)
count = count+1;
}
tk
u.
rem=n%i;
ur
}
if (count==1)
printf("\n The given number %d is a prime number", n);
else
printf("\n The given number %d is not a prime number", n);
}
}
8.
#include<stdio.h>
main()
{
int num, rem, temp, i, sum = 0;
printf("\n Enter the number of your choice: ");
scanf("%d", &num);
temp = num;
while(num != 0)
sv
ie
if(sum == temp)
tk
an
else
9.
ur
#include<stdio.h>
tk
u.
main()
if(rev == temp)
printf("\n The given number %d is a palindrome",temp);
else
printf("\n The given number %d is not a palindrome", temp);
}
10.
#include<stdio.h>
main()
{
sv
int i=0,j=1,k=2,r,f;
ie
scanf("%d",&r);
while(k<r)
{
f=i+j;
i=j;
printf(" \t%d",j);
k++;
u.
ur
j=f;
an
tk
printf("\t%d\t %d",i,j);
}
}
#include<stdio.h>
main()
{
int a,b,c,big;
printf("\nEnter three numbers of your choice:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is: %d",big);
}
tk
11.
SWITCH-CASE
12.
#include<stdio.h>
main()
{
char ch;
printf("\n Please enter a character of your choice: ");
sv
scanf("%c", &ch);
switch(ch)
{
case 'e' :
case 'o' :
case 'A' :
case 'E' :
ur
case 'I' :
an
case 'u' :
tk
case 'i' :
ie
case 'a' :
case 'O' :
break;
u.
}
}
tk
break;
{
printf("\n\tMENU");
printf("\n\t----");
printf("\n 1. Addition \n 2. Subtraction \n 3. Multiplication \n 4. Divison \n 5. Modulo Divison \n");
printf("\n Please enter your choice: ");
scanf("%d",&choice);
printf("\n Enter any two numbers of your choice: ");
scanf("%d %d", &num1, &num2);
sv
switch(choice)
{
num1,num2,num1+num2);
tk
break;
ie
an
break;
break;
ur
num1,num2,num1*num2);
num1,num2,num1/num2);
tk
break;
u.
case 5: printf("\n The modulo divison of the given numbers %d and %d is %d\n",
num1,num2,num1%num2);
break;
}
printf("\n Do you want to continue....Press \n(1) to continue\n(2) to quit the program\n");
scanf("%d",&ch);
}while(ch == 1);
}
#include<stdio.h>
main()
{
int num1, num2, num3;
printf("\n Enter any three numbers of your choice: ");
sv
ie
num2)&&(num1 > num3))? num1 : ((num2 > num3) && (num2 > num1))? num2 : num3, num1, num2, num3);
}
OPERATOR */
#include<stdio.h>
main()
{
y = (x > 0) ? 1 : (x < 0) ? -1 : 0;
printf("\n y = %d for x = %d \n", y, x);
tk
u.
scanf("%d", &x);
ur
int x, y;
an
tk
15. /* PROGRAM TO PRINT Y = 1 FOR X > 0, Y = 0 FOR X = 0, Y = -1 FOR X < 0 USING CONDITIONAL
sv
ie
tk
an
#include<stdio.h>
#define pi 3.1456
main()
tk
u.
#include<math.h>
ur
do
{
printf("\n\t\tMENU");
printf("\n\t\t----");
printf("\n 1. ax2+bx+c \n 2. b2-4ac / 2a \n 3. xlogx \n 4. cos2x +sin2x \n 5. Quit \n");
printf("\n Please enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\n Please enter the values of a, b, c and x: ");
scanf("%d %d %d %d", &a, &b, &c, &x);
equ = (a * pow(x,2) + b * x + c);
printf("\n The value of ax2+bx+c is %f", equ);
break;
ie
sv
tk
an
log = x*log10(x);
ur
break;
u.
x = x * (180/pi);
break;
case 5: exit(0);
tk
break;
default: printf("\n Please enter correct choice....");
}
printf("\n Do you want to continue....Press \n(1) to continue\n(2) to quit the program\n");
scanf("%d",&ch);
}while(ch == 1);
}
18. /* PROGRAM TO FIND THE AREA OF THE TRIANGLE WITH (I). GIVEN SIDES A, B, C (II).
GIVEN HEIGHT AND BREADTH */
#include<stdio.h>
#include<math.h>
main()
{
int choice, ch, a, b, c;
float x, s, area;
sv
do
{
printf("\n\t\tMENU");
ie
printf("\n\t\t----");
printf("\n 1. Area of Triangle given sides a, b and c \n 2. Area of triangle given breadth and height
tk
\n 3. Quit \n");
an
scanf("%d",&choice);
switch(choice)
ur
x = s*(s-a)*(s-b)*(s-c);
tk
area = sqrt(x);
u.
s = (float)((a+b+c)/2);
case 2: printf("\n Please enter the values of breadth and height: ");
scanf("%d %d", &b, &c);
area = (0.5 * b * c);
printf("\n The area of triangle is %f", area);
break;
case 3: exit(0);
break;
sv
#include<math.h>
#define pi 3.14159
main()
printf("\n\t\tMENU");
ur
printf("\n\t\t----");
an
tk
ie
switch(choice)
{
tk
u.
scanf("%d",&choice);
break;
case 3: exit(0);
break;
default: printf("\n Please enter correct choice....");
}
printf("\n Do you want to continue....Press \n(1) to continue\n(2) to quit the program\n");
scanf("%d",&ch);
}while(ch == 1);
sv
20. /* PROGRAM TO PRINT THE MAXIMUM AND MINIMUM ELEMENT FROM GIVEN ARRAY */
#include<stdio.h>
tk
ie
main()
an
scanf("%d",&n);
{
scanf("%d",&a[i]);
min = a[0];
for(i=0;i<n;i++)
{
if(a[i] > max)
{
max = a[i];
}
if(a[i] < min)
{
min = a[i];
tk
max = a[0];
u.
ur
for(i=0;i<n;i++)
}
}
printf("\n The given array is ");
for(i=0;i<n;i++)
{
printf("\t%d",a[i]);
}
printf("\n Maximum element in the given array is %d", max);
sv
main()
tk
ie
#include<stdio.h>
scanf("%d",&n);
an
for(i=0;i<n;i++)
{
u.
scanf("%d",&a[i]);
ur
scanf("%d", &search);
for(i=0;i<n;i++)
tk
printf("\n Please enter the number for which you want find the position: ");
{
if(a[i] == search)
{
pos += 1;
printf("\n The search element is present at position %d of the given array", i);
}
}
if(pos == 0)
{
printf("\n Sorry....The search element is not present in the given array");
}
}
22. /* PROGRAM TO INSERT A NUMBER IN TO AN ARRAY AT THE REQUIRED POSITION */
#include<stdio.h>
main()
sv
ie
{
scanf("%d", &x[i]);
}
an
tk
for(i=0;i<n;i++)
for(i=0;i<n;i++)
{
printf("\t%d",x[i]);
}
tk
u.
ur
printf("\n Please enter the number and position you want to enter into the array: ");
scanf("%d %d", &a, &pos);
if(pos < (n-1))
{
for(i=n-1;i>=0;i--)
{
x[i]= x[i-1];
if(i == pos)
{
x[i]=a;
break;
}
}
}
else
{
printf("\n Sorry....position exceeds array size....the element cannot be inserted");
}
sv
ie
printf("\t%d",x[i]);
}
tk
main()
{
scanf("%d", &x[i]);
tk
for(i=0;i<n;i++)
u.
ur
an
#include<stdio.h>
}
printf("\n The given array before deleting the element is :");
for(i=0;i<n;i++)
{
printf("\t%d",x[i]);
}
printf("\n Please enter the number you want to delete from the array: ");
scanf("%d", &a);
for(i=0;i<n;i++)
{
if(x[i] == a)
{
pos = i;
printf("\n The element %d has been removed from position %d of the array", a, pos);
for(i=pos;i<n;i++)
sv
x[i] = x[i+1];
ie
x[n-1] = 0;
}
if(pos == 0)
an
tk
ur
printf("\t%d",x[i]);
tk
u.
for(i=0;i<n;i++)
{
scanf("%d",&x[i]);
}
printf("\n The given array is ");
for(i=0;i<n;i++)
{
printf("\t%d",x[i]);
sv
{
if(search == x[i])
{
err += 1;
}
if(err == 0)
u.
ur
an
count += 1;
tk
ie
for(i=0;i<n;i++)
else
{
tk
#include<math.h>
main()
{
int x[10], n, i;
double total=0.0;
float sum=0.0,M,V,SD;
printf("\n Please enter size of the array: ");
scanf("%d",&n);
sv
ie
scanf("%d", &x[i]);
}
tk
printf("\t%d", x[i]);
for(i=0;i<n;i++)
{
total=total+pow(x[i],2);
M=sum/n;
V=total-pow(M,2);
tk
u.
sum=sum+x[i];
ur
an
SD=sqrt(V);
printf("\n Mean=%f\n Variance=%f\n Standard Deviation=%f", M,V,SD);
}
26. /* PROGRAM TO REVERSE THE ELEMENTS OF THE ARRAY */
#include<stdio.h>
main()
{
int a[10], i, n, t;
printf("\n Please enter array size: ");
scanf("%d",&n);
printf("\n Please enter the elements of the array: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sv
ie
printf("\t%d",a[i]);
for(i=0;i<n/2;i++)
t=a[i];
a[n-1-i]=t;
}
for(i=0;i<n;i++)
printf("\t%d",a[i]);
}
tk
u.
ur
a[i]=a[n-1-i];
an
tk
}
27. /* PROGRAM TO COUNT THE NO. OF EVEN NUMBERS AND NO. OF ODD NUMBERS IN A
GIVEN ARRAY */
#include<stdio.h>
main()
{
sv
ie
printf("\t%d",a[i]);
}
}
else
odd += 1;
tk
u.
ur
even += 1;
an
if((a[i]%2) == 0)
tk
for(i=0;i<n;i++)
printf("\n The number of even elements in the given array are %d", even);
printf("\n The number of odd elements in the given array are %d", odd);
}
sv
scanf("%d", &a[i][j]);
}
ie
}
printf("\n");
}
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(i == j)
{
sum = sum + a[i][j];
}
}
}
tk
u.
ur
printf("%4d", a[i][j]);
an
tk
29. /* PROGRAM TO ENTER AND PRINT THE ELEMENTS IN A DOUBLE DIMENSIONAL ARRAY */
#include<stdio.h>
main()
{
int a[10][10], rs, cs, i, j;
sv
printf("\n Please enter the row size and column size respectively: ");
scanf("%d %d", &rs, &cs);
ie
{
for(j=0; j<cs; j++)
{
scanf("%d", &a[i][j]);
}
}
tk
u.
ur
an
tk
printf("\t%d", a[i][j]);
}
}
printf("\n The elements of the given array in matrix form is: \n");
for(i=0; i<rs ; i++)
{
for(j=0; j<cs; j++)
{
printf("\t%d", a[i][j]);
}
printf("\n");
}
}
30. /* PROGRAM TO PRINT THE SUM OF (I) ALL ROW ELEMENTS (II) ALL COLUMN ELEMENTS
IN AN ARRAY */
sv
#include<stdio.h>
main()
{
ie
printf("\n Please enter the row size and column size respectively: ");
tk
tk
u.
scanf("%d", &a[i][j]);
ur
an
printf("\n The elements of the given array in matrix form is: \n");
for(i=0; i<rs ; i++)
{
for(j=0; j<cs; j++)
{
printf("\t%d", a[i][j]);
}
printf("\n");
}
sv
ie
sc = 0;
sc += a[j][i];
an
tk
ur
}
}
main()
tk
u.
#include<stdio.h>
printf("\n Please enter the row size and column size of matrix1 respectively: ");
scanf("%d %d", &rs1, &cs1);
printf("\n The size of the array is %d", rs1*cs1);
printf("\n Enter %d elements of the array: ", rs1*cs1);
for(i=0; i<rs1 ; i++)
{
for(j=0; j<cs1; j++)
{
scanf("%d", &a[i][j]);
}
}
printf("\n First matrix elements are: \n");
for(i=0; i<rs1 ; i++)
{
for(j=0; j<cs1; j++)
{
sv
printf("\t%d", a[i][j]);
printf("\n");
ie
printf("\n Please enter the row size and column size of matrix2 respectively: ");
tk
tk
u.
scanf("%d", &b[i][j]);
ur
an
}
}
ie
sv
test += 1;
tk
}
}
if(test == 0)
{
}
}
tk
u.
ur
printf("\n");
an
printf("\t%d", c[i][j]);
sv
for(j=0;j<c1;j++)
printf("%d\t",a[i][j]);
tk
ie
printf("\n");
printf("\n Enter row size and column size for second matrix: ");
scanf("%d %d", &r2, &c2);
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}
printf("\n The second matrix is:\n");
{
for(j=0;j<c2;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
if(c1 == r2)
{
printf("\n Matrix multiplication is possible....");
printf("The result of the multiplication is as follows:\n");
tk
for(i=0;i<r2;i++)
u.
ur
an
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j] += a[i][k]*b[k][j];
sv
printf("%d\t",mult[i][j]);
}
}
}
else
an
tk
ie
printf("\n");
ur
}
}
33. /* PROGRAM TO DISPLAY THE UPPER, LOWER MATRIX FOR A GIVEN ARRAY */
#include<stdio.h>
{
int x[10][10],i,j,k,rs,cs;
printf("\n Enter row size and column size of the matrix: ");
scanf("%d %d",&rs, &cs);
if(rs == cs)
{
printf("\n Enter %d elements into matrix: ", rs*cs);
for(i=0;i<rs;i++)
{
tk
main()
u.
for(j=0;j<cs;j++)
{
scanf("%d",&x[i][j]);
}
}
printf("\n The given matrix is:\n");
for(i=0;i<rs;i++)
{
sv
for(j=0;j<cs;j++)
printf("\t%d",x[i][j]);
ie
printf("\n");
tk
for(i=0;i<rs;i++)
{
for(j=0;j<cs;j++)
{
if(i >= j)
{
}
else
{
printf("\t%d",0);
}
}
printf("\n");
}
printf("\nUpper Triangular Matrix");
tk
printf("\t%d",x[i][j]);
u.
ur
an
printf("\n-----------------------\n");
printf("\n-----------------------\n");
for(i=0;i<rs;i++)
{
for(j=0;j<cs;j++)
{
if(i <= j)
{
printf("\t%d",x[i][j]);
sv
else
{
ie
printf("\t%d",0);
printf("\n");
ur
else
an
tk
u.
printf("\n Please try again with equal row size and column size\n");
tk
for(i=0;i<rs;i++)
{
for(j=0;j<cs;j++)
{
scanf("%d",&x[i][j]);
}
}
printf("\n The given matrix is:\n");
sv
for(i=0;i<rs;i++)
{
for(j=0;j<cs;j++)
ie
printf("\t%d",x[i][j]);
printf("\n");
an
tk
{
for(j=0;j<rs;j++)
printf("\t%d",x[j][i]);
printf("\n");
}
tk
u.
ur
for(i=0;i<cs;i++)
}
35. a. /* PROGRAM TO COPY ONE STRING INTO ANOTHER STRING WITH USE OF BUILT-IN
FUNCTIONS */
#include<stdio.h>
#include<string.h>
main()
{
sv
puts(str2);
strcpy(str1,str2);
ie
puts(str1);
tk
puts(str2);
IN FUNCTIONS */
main()
{
char str1[40], str2[20], i = 0, j;
printf("\n Please enter the first string: ");
tk
gets(str1);
u.
ur
#include<stdio.h>
an
b. /* PROGRAM TO COPY ONE STRING INTO ANOTHER STRING WITH OUT THE USE OF BUILT-
}
str1[i] = '\0';
str2[i] = '\0';
printf("\n The first string after copying is ");
puts(str1);
printf("\n The second string after copying is ");
puts(str2);
}
sv
36. a. /* PROGRAM TO CONCATENATE ONE STRING INTO ANOTHER STRING WITH USE OF
BUILT-IN FUNCTIONS */
#include<stdio.h>
main()
{
tk
ie
#include<string.h>
gets(str1);
ur
an
strcat(str1,str2);
printf("\n First string after concatenation is ");
puts(str1);
printf("\n Second string after concatenation is ");
puts(str2);
}
tk
puts(str2);
u.
puts(str1);
b. /* PROGRAM TO CONCATENATE ONE STRING INTO ANOTHER STRING WITHOUT THE USE
OF BUILT-IN FUNCTIONS */
#include<stdio.h>
main()
{
char str1[40], str2[20], i = 0, j;
printf("\n Please enter the first string: ");
gets(str1);
gets(str2);
sv
ie
puts(str1);
while(str1[i] != '\0')
i++;
tk
u.
ur
an
tk
puts(str2);
{
char str1[25], str2[25];
int i;
printf("\n Please enter the first string: ");
gets(str1);
printf("\n Please enter the second string: ");
gets(str2);
printf("\n First string before comparison is ");
sv
puts(str1);
ie
i = strcmp(str1,str2);
if(i == 0)
tk
else
an
printf("\n First string %s is smaller than second string %s ", str1, str2);
ur
printf("\n First string %s is greater than second string %s ", str1, str2);
}
b. /* PROGRAM TO COMPARE TWO STRINGS WITH OUT THE USE OF BUILT-IN FUNCTIONS */
main()
tk
u.
#include<stdio.h>
else
sv
ie
38. a. /* PROGRAM TO FIND THE LENGTH OF STRING WITH USE OF BUILT-IN FUNCTIONS */
#include<string.h>
int len;
printf("\n Please enter a string: ");
gets(str1);
printf("\n The entered string is ");
len = strlen(str1);
printf("\n The length of the given string is %d", len);
tk
puts(str1);
u.
ur
char str1[25];
an
main()
tk
#include<stdio.h>
}
b. /* PROGRAM TO FIND THE LENGTH OF STRING WITH OUT THE USE OF BUILT-IN
FUNCTIONS */
#include<stdio.h>
main()
{
char str[25], i = 0, len = 0;
sv
#include<string.h>
main()
{
an
char str1[25];
tk
ie
#include<stdio.h>
tk
puts(str1);
u.
ur
gets(str1);
b. /* PROGRAM TO CONVERT STRINGS FROM LOWER CASE TO UPPER CASE WITH OUT THE USE
OF BUILT-IN FUNCTION */
#include<stdio.h>
main()
{
char str[25], i;
printf("\n Please enter a string in lower case: ");
scanf("%s", str);
sv
str[i] = '\0';
tk
ie
printf("%s", str);
#include<string.h>
puts(str1);
strlwr(str1);
printf("\n The entered string after conversion is ");
puts(str1);
}
tk
u.
char str1[25];
ur
main()
an
#include<stdio.h>
sv
ie
tk
u.
ur
str[i] = '\0';
an
#include<string.h>
main()
{
char str1[25];
printf("\n Please enter a string: ");
gets(str1);
printf("\n The entered string is ");
puts(str1);
strrev(str1);
tk
#include<stdio.h>
gets(str);
sv
ie
puts(str);
len++;
for(i=0; i<len/2;i++)
temp = str[len-1-i];
str[len-1-i]= str[i];
puts(str);
}
tk
u.
str[i] = temp;
ur
an
tk
42. a. /* PROGRAM TO CHECK WHETHER A GIVEN STRING IS PALINDROME OR NOT WITH THE
USE OF BUILT-IN FUNCTIONS */
#include<stdio.h>
#include<string.h>
main()
{
char str1[25], temp[25];
int i;
printf("\n Please enter a string: ");
gets(str1);
printf("\n The entered string is ");
puts(str1);
strcpy(temp,str1);
strrev(str1);
i = strcmp(temp,str1);
sv
if(i == 0)
ie
tk
b. /* PROGRAM TO CHECK WHETHER A GIVEN STRING IS PALINDROME OR NOT WITH OUT THE
USE OF BUILT-IN FUNCTIONS */
#include<string.h>
{
char str1[25], temp[25];
tk
gets(str1);
u.
ur
main()
an
#include<stdio.h>
/* STRING REVERSING */
for(i=0; str1[i] != '\0'; i++)
{
len++;
}
for(i=0; i<len/2;i++)
{
temp1 = str1[len-1-i];
sv
str1[len-1-i]= str1[i];
str1[i] = temp1;
}
ie
/* STRING COMPARISON */
tk
{
if(str1[i] == temp[i])
an
count = 0;
else
}
if(count == 0)
tk
u.
ur
count = 1;
1
2
3
4
5
2
3
4
5
#include<stdio.h>
3
4
4
5
*/
main()
{
int i, j, k, n;
printf("\n Please enter a number: ");
scanf("%d", &n);
for(i=0; i<=n; i++)
{
for(k=1; k<=n-i;k++)
sv
printf(" ");
}
ie
ur
an
printf("\n");
tk
printf("%2d", i);
44. /* PROGRAM TO MENU DRIVEN PROGRAM TO PERFORM THE OPERATIONS ADD, SUBTRACT,
MULTIPLY, DIVIDE OF TWO COMPLEX NUMBERS X+IY, A+IB USING FUNCTIONS */
tk
u.
#include<stdio.h>
printf("\n The sum of the two complex numbers is %d+i%d", x1+a1, y1+b1);
}
void sub(int *x2, int *y2, int *a2, int *b2)
{
*x2 = *x2 - *a2;
*y2 = *y2 - *b2;
}
void mult()
{
int x, y, a, b;
printf("\n Enter two numbers for the first complex number: ");
scanf("%d %d", &x, &y);
printf("\n Enter two numbers for the second complex number: ");
scanf("%d %d", &a, &b);
printf("\n The Multiplication of the two complex numbers is %d+i%d", x*a - y*b, x*b + y*a);
}
void div()
sv
int x, y, a, b;
printf("\n Enter two numbers for the first complex number: ");
ie
printf("\n Enter two numbers for the second complex number: ");
tk
printf("\n The Division of the two complex numbers is %d+i%d", (x*a + y*b)/(a*a + b*b), (y*a -
}
main()
{
int x, y, a, b, choice, ch, res;
float res1;
do
{
tk
u.
ur
an
x*b)/(a*a + b*b));
add(x, y, a, b);
break;
case 2: printf("\n Enter two numbers for the first complex number: ");
scanf("%d %d", &x, &y);
printf("\n Enter two numbers for the second complex number: ");
scanf("%d %d", &a, &b);
sub(&x, &y, &a, &b);
printf("\n The difference of the two complex numbers is %d+i%d", x, y);
sv
break;
case 3: mult();
break;
ie
case 4: div();
break;
tk
case 5: return(0);
an
printf("\n Do you want to continue....\n Press 1 for YES \n Press 2 for NO\n ");
}while(ch == 1);
}
u.
ur
scanf("%d",&ch);
45. /* PROGRAM TO FIND THE SUM OF ALL ELEMENTS IN AN ARRAY BY USING FUNCTIONS
WITH ARGUMENTS AND NO RETURN VALUES */
main()
{
void arraysum(int [], int );
int a[10], n, i;
printf("\n Please enter size of the array: ");
scanf("%d", &n);
printf("\n Please enter the values of the array \n");
for(i=0; i<n; i++)
{
tk
#include<stdio.h>
scanf("%d",&a[i]);
}
printf("\n The array elements are....");
for(i=0; i<n; i++)
{
printf("\t%d",a[i]);
}
arraysum(a,n);
sv
an
tk
ie
int i, sum = 0;
printf("\n The sum of all the elements in the array is %d\n", sum);
ur
tk
u.
main()
int n;
do
ie
sv
int factorial(int );
if(n<0)
tk
scanf("%d", &n);
}while(n<0);
an
}
int factorial(int x)
if(x==0)
else
return x*factorial(x-1);
tk
return 1;
u.
ur
}
48. /* PROGRAM TO CALCULATE THE FIBONACCI SERIES BY USING RECURSION */
#include<stdio.h>
main()
{
int fib(int oldvalue, int newvalue, int no);
int range, fib1 = 0,fib2 = 1;
while (n!=2)
{
ie
sv
int sum;
new_val = sum;
}
}
tk
u.
ur
return(0);
an
n -= 1;
tk
old_val = new_val;