0% found this document useful (0 votes)
3 views

PPS LAB PROGRAMS

The document contains a series of C programming exercises covering various topics such as conversions, calculations, and conditionals. Each exercise includes a problem statement, input/output specifications, and example test cases. The document also provides complete C code solutions for each problem.

Uploaded by

krisis0017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PPS LAB PROGRAMS

The document contains a series of C programming exercises covering various topics such as conversions, calculations, and conditionals. Each exercise includes a problem statement, input/output specifications, and example test cases. The document also provides complete C code solutions for each problem.

Uploaded by

krisis0017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

PPS LAB PROGRAMS

/*

QUESTION:

1a. Write a C program to convert days into years, weeks and days.(Assume a year has 365 days)

INPUT: 1 NUMBER OF TYPE INT

OUTPUT: 3 INTEGERS AS SHOWN IN THE TEST CASE.

Case=t4

Input= 1238

Output=

1238 Days = 3 Years 20 Weeks and 3 Days.

*/

// start program from here......

program:
#include<stdio.h>

int main()

int days,y,d,w;

scanf("%d",&days);

y=days/365;

w=(days%365)/7;

d=(days%365)%7;

printf("%d Days = %d Years %d Weeks and %d Days.",days,y,w,d);

return 0;

--------------------------------------------------------------------------------------------------------------------------
/*

QUESTION

1b. Write a C program to find greatest and smallest among three numbers using conditional operator.

INPUT: 3 INTEGERS

OUTPUT: 2 INTEGERS AS PER THE TEST CASE FORMAT

Test cases:

Case=t3

Input=

123 765 -763

Output=

Greatest among 123 , 765 and -763 = 765

Smallest among 123 , 765 and -763 = -763

*/

// write a program next line....

program:
#include<stdio.h>

int main()

int min,max,a,b,c;

scanf("%d%d%d",&a,&b,&c);

max=(a>b)?((a>c)?a:c):((b>c)?b:c);

min=(a<b)?((a<c)?a:c):((b<c)?b:c);

printf("Greatest among %d , %d and %d = %d\n",a,b,c,max);

printf("Smallest among %d , %d and %d = %d\n",a,b,c,min);

return 0;

}
/*

QUESTION:

1c. Write a C program to enter P, T, R and calculate Compound Interest.

INPUT:READ 3 NUMBERS P,T,R AS INT,INT AND FLOAT RESPECTIVELY

OUTPUT: DISPLAY COMPUND INTEREST AS FLOAT UPTO 2 DECIMAL POINTS AS PER TEST CASE FORMAT

Test cases:

Case=t3

Input=10000 3 12.65

Output=

Compound Interest = 14295.31

*/

// start program here.....

program:
#include<stdio.h>

#include<math.h>

int main()

int p,t;

float r,c;

scanf("%d%d%f",&p,&t,&r);

c=(p*(pow((1+r/100),t)));

printf("Compound Interest = %0.2f",c);

return 0;

/*

QUESTION

2a. 2A)Write a C program to swap two numbers using the following:


(i) Using third variable (ii) without using third variable (iii) Using bitwise operators

INPUT FORMAT : READ TWO INTEGERS 3 DIFFERENT TIMES AS PER TEST CASE

OUTPUT FORMAT: DISPALY THE SWAPPED VALUES AS PER GIVEN TEST CASE FORMAT

Test cases:

case=t4

input=

58

-8 76

9 56

output=

USING THIRD VARIABLE TO SWAP 2 NUMBERS

BEFORE SWAP a = 5 and b = 8

AFTER SWAP a = 8 and b = 5

WITHOUT USING THIRD VARIABLE TO SWAP 2 NUMBERS

BEFORE SWAP a = -8 and b = 76

AFTER SWAP a = 76 and b = -8

USING BITWISE OPERATORS TO SWAP 2 NUMBERS

BEFORE SWAP a = 9 and b = 56

AFTER SWAP a = 56 and b = 9

*/

//strat program from here....

program:
# include <stdio.h>

int main()

{
int a,b,c,x,y,k,w;

scanf("%d%d%d%d%d%d",&a,&b,&x,&y,&k,&w);

c=a;

a=b;

b=c;

x=x+y;

y=x-y;

x=x-y;

k=k^w;

w=k^w;

k=k^w;

printf("USING THIRD VARIABLE TO SWAP 2 NUMBERS\n");

printf("BEFORE SWAP a = %d and b = %d\n",b,a);

printf ("AFTER SWAP a = %d and b = %d\n",a,b);

printf("WITHOUT USING THIRD VARIABLE TO SWAP 2 NUMBERS\n");

printf("BEFORE SWAP a = %d and b = %d\n",y,x);

printf("AFTER SWAP a = %d and b= %d\n",x,y);

printf("USING BITWISE OPERATORS TO SWAP 2 NUMBERS\n");

printf("BEFORE SWAP a = %d and b = %d\n",w,k);

printf("AFTER SWAP a = %d and b = %d",k,w);

return 0;

/*

2B (i,ii) Write a C program to do the following using implicit and explicit type conversion

(i) Convert Celsius temperature to Fahrenheit.

(ii) Convert Fahrenheit temperature to Celsius.

TEST CASE:

case=t6
input=

5.6 18.8

output=

5.6 FARENHEIT = -14.7 CELCIUS

18.8 CELCIUS = 65.8 FARENHEIT

INPUT FORMAT : READ CELSIUS AND FARENHEIT TEMPERATURE AS A FLOAT VALUES

OUTPUT FORMAT: DISPALY THE FARENHEIT AND CELCIUS TEMPERATURES IN GIVEN TEST CASE FORMAT
UPTO ONE DECIMAL POINTS.

*/

//start program from next line....... 5/9*(c-32);

program:
#include<stdio.h>

int main()

float a,c,b,d;

scanf("%f",&a);

b=(float)5/9*(a-32);

printf("%.1f FARENHEIT = %.1f CELCIUS",a,b);

scanf("%f",&c);

d=(float)9/5*c+32;

printf("\n%.1f CELCIUS = %.1f FARENHEIT",c,d);

return 0;

/*

QUESTION:

2 B (iii) Write c program to use implicit and explicit conversion to Find area of a triangle given sides a,b,c

Note: s= (a+b+c)/2 , sqrt(s*(s-a)*(s-b)*(s-c))


INPUT FORMAT: READ THREE SIDES AS INTEGERS

OUTPUT FORMAT: DISPLAY AREA(DOUBLE TYPE) UPTO TWO DECIMAL VALUES AS PER TEST CASE

Test cases:

Case=t2

Input=12 10 8

Output=

Area of Triangle whose sides are 12 , 10 and 8 = 39.69 Square.Units

*/

//start program from next line…

program:
#include<stdio.h>

#include<math.h>

int main()

int a,b,c;

float s,area;

scanf("%d%d%d",&a,&b,&c);

s=(float)(a+b+c)/2;

area=sqrt(s*(s-a)*(s-b)*(s-c));

printf("Area of Triangle whose sides are %d , %d and %d = %.2f Square.Units.",a,b,c,area);

return 0;

/*

3a. Write a C program to add two numbers without using arithmetic operators in C.

INPUT FORMAT: READ TWO NUMBERS AS TWO POSITIVE INTEGERS

OUTPUT FORMAT: DISPLAY THE RESULT IN BELOW GIVEN TEST CASE FORMAT.

Test Cases:
case=t1

Input= 4 5

Output=

SUM OF 4 and 5 IS = 9

*/

//start program from next line.....

program:
#include<stdio.h>

int main()

int a,b,d;

scanf("%d%d",&a,&b);

d=printf("%*c%*c",a,' ',b,' ');

printf("SUM OF %d and %d IS = %d",a,b,d);

return 0;

/*

3b. Write a C program to determine whether a number is a power of 2 or not using bitwise operator and
ternary operator.

INPUT FORMAT : READ THE NUMBER AS INTEGER

OUTPUT FORMAT: DISPLAY THE RESULT AS PER GIVEN TEST CASE

Test cases:

Case=t1

Input=256

Output=

256 is a Power of 2

Case=t2
Input=22

Output=

22 is not a Power of 2

*/

//start program from next line....

program:
#include<stdio.h>

int main()

int n;

scanf("%d",&n);

((n&(n-1))==0)?printf("%d is a Power of 2",n):printf("%d is not a Power of 2",n);

return 0;

/*

3c. Write a C program to check whether a number is even or odd using bitwise operator and ternary
operator.

INPUT FORMAT : READ THE NUMBER AS INTEGER

OUTPUT FORMAT: DISPLAY THE RESULT AS PER TEST CASE.

Test Cases:

Case=t1

Input=4

Output=

4 is an Even Number.

Case=t2
Input=21

Output=

21 is an Odd Number.

*/

//strat progrm from next line....

program:
#include<stdio.h>

int main()

int n;

scanf("%d",&n);

((n&1)==0)?printf("%d is an Even Number",n):printf("%d is an Odd Number",n);

return 0;

/*

4a. Write a C program to find the roots of a quadratic equation using if-else.

INPUT: READ 3 INTEGERS CHOICE,NO1,NO2.

OUTPUT: DISPLAY AS PER GIVEN TEST CASE FORMAT.

Test Cases:

case=t1

Input = 1 -8 -6

Output =

Roots are real and distinct:

Root 1 = 8.690

Root 2 = -0.690

*/

//start program from next line......


program:
#include <math.h>

#include <stdio.h>

int main()

double a, b, c, d, root1, root2, realPart, imagPart;

scanf("%lf%lf%lf", &a, &b, &c);

d = b * b - 4 * a * c;

if (d > 0)

root1 = (-b + sqrt(d)) / (2 * a);

root2 = (-b - sqrt(d)) / (2 * a);

printf("Roots are real and distinct:\n");

printf("Root 1 = %.3lf \nRoot 2 = %.3lf", root1, root2);

else if (d == 0)

root1 = root2 = -b / (2 * a);

printf("Roots are real and repeated:\n");

printf("Root 1 = Root 2 = %.3lf", root1);

else

realPart = -b / (2 * a);

imagPart = sqrt(-d) / (2 * a);

printf("Roots are complex:\n");

printf("Root 1 = %.3lf + %.3lfi \nRoot 2 = %.3f - %.3fi", realPart, imagPart, realPart, imagPart);

}
return 0;

/*

4b. Write a C program to input electricity unit charges and calculate total electricity bill according to the
given condition:

For first 50 units Rs. 0.50/unit

For next 100 units Rs. 0.75/unit

For next 100 units Rs. 1.20/unit

For unit above 250 Rs. 1.50/unit

An additional surcharge of 20% is added to the bill

Test Cases:

case=t1

input=50

output=

Electricity Bill = Rs.30.00

*/

//start program from next line.....

program:
#include<stdio.h>

int main(){

int u;

float cost,sur;

scanf("%d",&u);

if(u<=50){

cost=u*0.50;

}else if(u>50&&u<=150){
cost=25+(u-50)*0.75;

}else if(u>150&&u<=250){

cost=100+(u-150)*1.20;

}else{cost=220+(u-250)*1.50;}

sur=cost+cost*(.20);

printf("Electricity Bill = Rs.%0.2f",sur );

return 0;

//cost+cost*((float)20/100)

/*

QUESTION:

4c. Write a menu driven C program to implement a simple arithmetic calculator.

INPUT: READ 3 INTEGERS CHOICE,NO1,NO2.

OUTPUT: DISPLAY AS PER GIVEN TEST CASE FORMAT.

ASLO TEST FOR INVALID CHOICE.

Test Cases:

case = t4

input=

5 10 15

output=

Modulo-Division (Remainder) : 10 % 15 = 10

case = t5

input=

1 -6 23

output=

Addition : -6 + 23 = 17
*/

//start program from next line......

program:
#include<stdio.h>

int main()

int choice,a,b;

scanf("%d%d%d",&choice,&a,&b);

switch(choice){

case 1 : printf("Addition : %d + %d = %d",a,b,a+b);

break;

case 2 : printf("Subtracion : %d - %d = %d",a,b,a-b);

break;

case 3 : printf("Multiplication : %d * %d = %d",a,b,a*b);

break;

case 5 : printf("Modulo-Division (Remainder) : %d %% %d = %d",a,b,a%b);

break;

case 4 : if(b==0)

printf("Divisor can not be zero.");

else

printf("Division (Quotient) : %d / %d = %d",a,b,a/b);


}

break;

default :printf("Invalid Choice");

break;

return 0;

/*

4d. Write a C program to display number of days in month using switch case (The input is month number
1 -12).

Test Cases:

case=t1

input=

output=

May 31 days

*/

//start program from next line.....

program:
#include<stdio.h>

int main()

int choice;

scanf("%d",&choice);

switch(choice)

case 1: printf("Jan 31 days");

break;
case 2: printf("February 28 days");

break;

case 3: printf("March 31 days");

break;

case 4: printf("April 30 days");

break;

case 5: printf("May 31 days");

break;

case 6: printf("June 30 days");

break;

case 7: printf("July 31 days");

break;

case 8: printf("August 31 days");

break;

case 9: printf("September 30 days");

break;

case 10: printf("October 31 days");

break;

case 11: printf("November 30 days");

break;

case 12: printf("December 31 days");

break;

default : printf("Invalid Choice");

break;

return 0;

/*

5a. Write a C Program check whether a given number is Perfect number or not.
Test Cases:

case=t1

case=t4

input=

496

output=

496 is a Perfect Number

case=t5

input=

10

output=

10 is a not Perfect Number

*/

//start program from next line......

program:
#include<stdio.h>

#include<stdlib.h>

int main()

int n,i,result=0;

scanf("%d",&n);

if(n<0)

printf("Invalid Input");

exit(0);

if(n==0)

{
printf("%d is not a Perfect Number",n);

exit(0);

for(i=1;i<n;i++)

if(n%i==0)

result=result+i;

if(result==n)

printf("%d is a Perfect Number",n);

else

printf("%d is not a Perfect Number",n);

/*

5b. Write a C Program check whether a given number is Palindrome number or not.

Test Cases:

case=t1

input=

121

output=

121 is a Palindrome.

case=t3

input=

125

output=

125 is not a Palindrome.

case=t8
input=

-7

output=

Invalid Input*/

program:
#include<stdio.h>

#include<stdlib.h>

int main()

int n,m,rev=0,rem;

scanf("%d",&n);

m=n;

if(n<0)

{printf("Invalid Input");

exit(0);

while(n!=0)

rem=n%10;

rev=rev*10+rem;

n=n/10;

if(m==rev)

printf("%d is a Palindrome.",m);

else

printf("%d is not a Palindrome.",m);

return 0;
}

/*

5c. Write a C Program check whether a given number is Armstrong number or not.

Test Cases:

case=t1

input=

371

output=

371 is an Armstrong Number.

case=t2

input=

111

output=

111 is not an Armstrong Number.

*/

//star program from next line…

program:
#include<stdio.h>

#include<math.h>

#include<stdlib.h>

int main()

int n,sum=0,r,m,a=0;

scanf("%d",&n);

if(n<0)

{
printf("Invalid Input");

exit(0);

m=n;

while(m!=0)

m=m/10;

a++;

m = n;

while(n!=0)

r=n%10;

sum=sum+pow(r,a);

n=n/10;

if(sum==m)

printf("%d is an Armstrong Number.",m);

else

printf("%d is not an Armstrong Number.",m);

return 0;

/*

5d. Write a C Program check whether a given number is Strong number or not

Test Cases:

case=t1

input=

output=
1 is a Strong number.

case=t5

input=

123

output=

123 is not a Strong number.

*/

//start program from next line....

program:
#include<stdio.h>

#include<stdlib.h>

int main()

int i, n, num, ldigit, sum=0,fact=1;

scanf("%d",&num);

n = num;

if(n==0)

printf("%d is not a Strong number.",n);

exit(0);

while(num > 0)

ldigit = num % 10;

fact = 1;

for(i=1; i<=ldigit; i++)

fact = fact*i;
}

sum = sum + fact;

num = num / 10;

if(n<0)

printf("Invalid Input");

else if(sum==n)

printf("%d is a Strong number.", n);

else

printf("%d is not a Strong number.", n);

return 0;

/*

6a . Write a C program to display the following patterns.

i) ****

* *

* *

****

Test Cases:

case=t1

input=5

output=

*****

* *

* *

* *

*****
*/

// start program from next line.....

program:
#include<stdio.h>

int main()

int i,j,n;

scanf("%d",&n);

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

if(i==1||i==n||j==1||j==n)

printf("*");

else

printf(" ");

printf("\n");

return 0;

/*

6a ii . Write a C program to display the following patterns.

ii) 1

2 3

4 5 6

7 8 9 10
Test Cases:

case=t1

input=5

output=

2 3

4 5 6

7 8 9 10

11 12 13 14 15

*/

//start program from next line......

program:
#include <stdio.h>

int main() {

int n, i, j, k,c = 1;

printf("Enter the number of rows: ");

scanf("%d", &n);

for (i = 1; i <= n; i++)

for (j = 1; j <= n-i; ++j)

printf(" ");

for(k=1;k<=i;k++)

printf("%d ",c);

c++;
}

printf("\n");

return 0;

/*

6a iii . Write a C program to display the following patterns.

iii) 1

22

333

4444

Test Cases:

case=t1

input=3

output=

22

333

*/

//start program from next line.....

program:
#include<stdio.h>

int main()

int i,j,n;

scanf("%d",&n);

for(i=1;i<=n;i++)
{

for(j=1;j<=i;j++)

printf("%c ",j+64);

printf("\n");

return 0;

/*

6b. write a c program to generate the prime numbers between x and y where x and y are starting and
ending values to be supplied by the user.

Test Cases:

case = t3

input=

1000 1100

output=

Prime Numbers between 1000 and 1100 are -

1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097

INPUT FORMAT: READ TWO POSITIVE INTEGERS X,Y

OUTPUT FORMAT:DISPLAY THE PRIME NUMBERS SEPERATED WITH A SPACE AS PER TEST CASE FORMAT

*/

//strat program from next line......

program:
#include<stdio.h>

int main()

int n,m,i,j,c;

scanf("%d%d",&n,&m);

printf("Prime Numbers between %d and %d are -\n",n,m);

for(i=n;i<=m;i++)

c=0;

for(j=1;j<=i;j++)

if(i%j==0)

c++;

if(c==2)

printf("%d ",i);

return 0;

/*

6c. Write a C program to calculate the sum of following series:

(i) S1=1+x^1/1!-x^2 /2!+x^3/3!-x^4/4!+…..x^n/n!

Test Cases:

case=t3

input= -1 3

output=
SUM = -0.666667

case=t4

input= 1 3

output=

SUM = 1.666667

INPUT FORMAT: READ TWO INTEGERS X,N

OUTPUT FORMAT: DISPLAY SUM AS PER THE GIVEN TEST CASE FORMAT

*/

//strat program from next line.....

program:
#include <stdio.h>

#include <math.h>

int main()

float num,x,sum=1,fact=1;

scanf("%f%f",&num,&x);

for(int i=1,m=2;i<=x;i++,m++)

fact*=i;

sum=sum+(pow(-1,m)*(pow(num,i))/fact);

printf("SUM = %f",sum);

return 0;

/*
6c. Write a C program to calculate the sum of following series:

(ii) S2= x^1/1+x^3/3+x^5/5+….+x^n/n

TEST CASE:

case=t2

input= 4 5

output=

SUM OF THE SERIES = 230.13

case=t3

input= -2 3

output=

SUM OF THE SERIES = -4.67

INPUT FORMAT: READ TWO INTEGERS X,N

OUTPUT FORMAT: DISPLAY SUM AS PER THE GIVEN TEST CASE

*/

//start program from next line......

program:
#include<stdio.h>

#include<math.h>

int main()

int x,n,i;

float s=0.0;

scanf("%d%d",&x,&n);

for(i=1;i<=n;i=i+2)

s=s+(float)pow(x,i)/i;
printf("SUM OF THE SERIES = %0.2f",s);

return 0;

/*

Write a C program to find sum, average and minimum and maximum in a list of numbers

Consider max size as 10.

Case = t2

Input = 5

9 6 90 123 65

Output =

SUM = 293

AVERAGE = 58.60

MINIMUM ELEMENT = 6 found at a[1]

MAXIMUM ELEMENT = 123 found at a[3]

Input Format:Read the size of the array in first line, Read the elements of array in second line seperated
by space.

Output Format : The output is Sum, Avg upto 2 decimals, Minimum and Maximum element of array
printed in separate line as per the test case.

// Start Writing your program from here..!!*/

program:
#include <stdio.h>

int main()

{ int n,sum=0,l1,l2;

float avg=0;

scanf("%d",&n);

int a[n];
for(int i=0; i<n; i++){

scanf("%d",&a[i]);

for(int i=0; i<n; i++){

sum+=a[i];

printf("SUM = %d\n",sum);

avg = (float)sum/n;

printf("AVERAGE = %.2f\n",avg);

int min = a[0];

for(int i=0; i<n; i++)

if(a[i]<min)

min = a[i];

l1 = i;

int max = a[0];

for(int i=0; i<n; i++)

{
if(a[i]>max)

max = a[i];

l2 = i;

printf("MINIMUM ELEMENT = %d found at a[%d]\n",min,l1);

printf("MAXIMUM ELEMENT = %d found at a[%d]\n",max,l2);

return 0;

/*

Write a C program to implement linear search.

TEST CASE:

Case = t1

input = 4

109 56 167 67

100

output =

LINEAR SEARCH UNSUCCESSFUL : 100 is NOT found in the list.

Case = t2

input = 6

2 7 5 -7 6 1

output =
LINEAR SEARCH SUCCESSFUL : 5 is found at a[2] in the list.

Input Format: Read the number of elements in array in first line, Enter the elements in second line
separated by space,

Enter the element to search in 3rd line

Output Format : The output is search successful element found at particular position based on search
key.

// Start Writing your program from here..!!*/

program:
#include<stdio.h>

int main()

int a[10],i,n,key;

scanf("%d",&n);

for(i=0;i<n;i++)

scanf("%d",&a[i]);

scanf("%d",&key);

for(i=0;i<n;i++)

if(key==a[i])

printf("LINEAR SEARCH SUCCESSFUL : %d is found at a[%d] in the list.",key,i);

break;

if(i==n)

printf("LINEAR SEARCH UNSUCCESSFUL : %d is NOT found in the list.",key);

return 0;
}

/*

7C. Write a C program to implement BINARY search.

Test Cases :

Case = t2

input = 5

10 20 30 40 50

20

output =

BINARY SEARCH SUCCESSFUL : 20 is found at a[1] in the list.

Case = t3

input = 5

10 45 67 89 100

89

output =

BINARY SEARCH SUCCESSFUL : 89 is found at a[3] in the list.

Input Format: Read the number of elements in array in first line, Enter the elements in second line
separated by space,

Enter the element to search in 3rd line

Output Format : The output is search successful element found at particular position based on search
key.

// Start Writing your program from here..!!*/

program:
#include <stdio.h>

int main()
{

int a[50],n,i,low,high,mid,key;

scanf("%d", &n);

for(i=0;i<n;i++)

scanf("%d",&a[i]);

scanf("%d",&key);

low=0;

high=n-1;

mid=(low+high)/2;

while(low<=high)

if(a[mid]<key)

low=mid+1;

else if(a[mid]==key)

printf("BINARY SEARCH SUCCESSFUL : %d is found at a[%d] in the list.\n", key, mid);

break;

else

high=mid-1;

mid=(low+high)/2;

if(low>high)

printf("BINARY SEARCH UNSUCCESSFUL : %d is NOT found in the list.\n",key);

return 0;
}

/*Write a C program to implement matrix addition

Case = t3

Input = 2 3 2 3

123456

123456

output =

MATRIX ADDITION IS POSSIBLE

SUM MATRIX C

2 4 6

8 10 12

Case = t4

Input = 2 3 3 3

output =

MATRIX ADDITION IS NOT POSSIBLE

Input Format: Read the order of both the matrices in first line.

In the second line first matrix elements seperated by space.

in the third line second matrix elements seperated by space.

Output Format :Print the resultant matrix is or print Matrix Addition is not possible as shown in the test
case.

*/

// Start Writing your program from here..!!

program:
#include<stdio.h>

void main()

int m,n,i,j,a,b;

scanf("%d%d%d%d",&m,&n,&a,&b);

int C[m][n];

int B[m][n];

int A[m][n];

if(m==a && n==b)

printf("MATRIX ADDITION IS POSSIBLE\n");

printf("SUM MATRIX C\n");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf("%d",&A[i][j]);

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf("%d",&B[i][j]);

}
}

for(i=0;i<m;i++)

for(j=0;j<n;j++)

C[i][j]=A[i][j]+B[i][j];

for(i=0;i<m;i++)

for(j=0;j<n;j++)

printf("\t%d",C[i][j]);

printf("\n");

else

printf("MATRIX ADDITION IS NOT POSSIBLE");

/*

8b. Write a C program to implement matrix multiplication.

Test Cases :

Case = t3

Input = 2 3 3 2
123456

123456

output =

MATRIX MULTIPLICATION IS POSSIBLE

PRODUCT MATRIX C

22 28

49 64

Case = t4

Input = 3 2 3 2

output =

MATRIX MULTIPLICATION IS NOT POSSIBLE

Input Format: Read the input matrix as integer based on dimensions. (first line the number of elements
in matrix, second line first matrix elements

third line second matrix elements)

Output Format :print resultant matrix is or print multiplication is not possible if matrix dimension is not
same.

*/

// Start Writing your program from here..!!

program:
#include <stdio.h>

int main(){

int x,y,p,q;

int a[10][10],b[10][10],c[10][10];

scanf("%d%d%d%d",&x,&y,&p,&q);
if(y==p){

for(int i=0; i<x; i++){

for(int j=0; j<y; j++){

scanf("%d",&a[i][j]);

for(int i=0; i<p; i++){

for(int j=0; j<q; j++){

scanf("%d",&b[i][j]);

for(int i=0; i<x; i++){

for(int j=0; j<y; j++){

c[i][j] = 0;

for(int k=0; k<y; k++){

c[i][j]+=a[i][k]*b[k][j];

printf("MATRIX MULTIPLICATION IS POSSIBLE\n");

printf("PRODUCT MATRIX C\n");

for(int i=0; i<x; i++){

for(int j=0; j<q; j++){

printf("%d\t",c[i][j]);

printf("\n");

}else{

printf("MATRIX MULTIPLICATION IS NOT POSSIBLE\n");


}

return 0;

/*

9a. Write a C program to display binary equivalent of a given decimal number using functions

Test cases:

case=t1

Input =34

output =Decimal Number=34 its Binary equivalent=100010

*/

//start program from next line......

program:
#include<stdio.h>

long toBin(int);

int main()

long bno;

int dno;

scanf("%d",&dno);

bno=toBin(dno);

printf("\nDecimal Number=%d its Binary equivalent=%ld\n\n",dno,bno);

return 0;

long toBin(int dno)

long bno=0,remainder,f=1;

while(dno!=0)
{

remainder=dno%2;

bno=bno+remainder*f;

f=f*10;

dno=dno/2;

return bno;

—---------------------------------------------------------------------------------------------------------------------

/*

9b. Write a C program to implement transpose of a matrix using functions.

Test cases:

case=t1

Input =2 2

1265

output =

Original Matrix

1 2

6 5

Transpose Matrix

1 6

2 5

*/

//start program from next line......


program:
#include<stdio.h>

void transpose(int row,int col,int a[row][col]){

int b[col][row],i,j;

for(i=0;i<row;i++)

for(j=0;j<col;j++)

b[j][i]=a[i][j];

printf("Transpose Matrix\n");

for(i=0;i<col;i++){

for(j=0;j<row;j++)

printf("%d ",b[i][j]);

printf("\n");

int main(){

int i,j,r,c;

scanf("%d%d",&r,&c);

int a[r][c];

for(i=0;i<r;i++){

for(j=0;j<c;j++)

scanf("%d",&a[i][j]);

}printf("Original Matrix\n");
for(i=0;i<r;i++){

for(j=0;j<c;j++)

printf("%d ",a[i][j]);

printf("\n");

transpose(r,c,a);

return 0;

/*

9c. Write a C program using functions that compares two strings to see whether they are identical or not.
The function returns 1 if they are identical, 0 otherwise.

Test cases:

case=t1

input=clanguage clanguage

output=

Strings s1 = clanguage and s2 = clanguage are identical

*/

//start program from next line......

program:
#include <stdio.h>

#include <string.h>

void compare(char s1[],char s2[])

{
if(strcmp(s1,s2)==0)

printf("Strings s1 = %s and s2 = %s are identical",s1,s2);

else

printf("Strings s1 = %s and s2 = %s are not identical",s1,s2);

void main()

char str1[100],str2[100];

scanf("%s%s",str1,str2);

compare(str1,str2);

/*

10a. Write a C program to implement factorial of a given integer using recursive and nonrecursive
functions.

case = t2

input = 5

output =

Factorial of 5 using Iteration is : 120

Factorial of 5 using Recursion is : 120

*/

//start program from next line......

program:
#include<stdio.h>

long int Recursion(int);

long int Iteration(int);

int main()

int n;

scanf("%d",&n);

if(n<0)

printf("Invalid Input");

else

printf("\nFactorial of %d using Iteration is : %ld\n",n,Iteration(n));

printf("Factorial of %d using Recursion is : %ld",n,Recursion(n));

return 0;

long int Recursion(int n)

if(n==0)

return 1;

else

return(n*Recursion(n-1));

long int Iteration(int n)


{

long int fact=1;

for(int i=1;i<=n;i++)

fact=fact*i;

return fact;

—---------------------------------------------------------------------------------------------------------------------------------

/*

10b. Write a C program to implement GCD of a given 2 integers using recursive and nonrecursive
functions.

case=t4

input=36 180

output=

GCD of 36 and 180 using Iteration is : 36

GCD of 36 and 180 using Recursion is : 36

*/

//start program from next line......

program:
#include<stdio.h>

int gdc (int n,int m)

{
int i,max=0;

for(i=1;i<=n&&i<=m;i++)

if(n%i==0&&m%i==0)

if(i>max)

max=i;

return max;

int gdcr(int n,int m)

if(m==0)

return n;

else

return gdcr(m,n%m);

int main()

int n,m,x,y;

scanf("%d%d",&n,&m);
x=gdc(n,m);

printf("\nGCD of %d and %d using Iteration is : %d\n",n,m,x);

y=gdcr(n,m);

printf("GCD of %d and %d using Recursion is : %d\n",n,m,y);

return 0;

—----------------------------------------------------------------------------------------------------------------------------------------
-------

/*

10c.Write a C program to print first ‘n’ terms of Fibonacci series using recursive and nonrecursive
functions.

case=t4

input=15

output=

Fibonacci Series using Iteration is :

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Fibonacci Series using Recursion is :

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

*/

//start program from next line......

program:
#include <stdio.h>
int fib(int n)

if (n <= 1 ) return n;

return fib(n-1) + fib(n-2);

void ite(int n) {

int a = 0, b = 1;

printf("Fibonacci Series using Iteration is :\n");

for (int i = 0; i < n; i++) {

int next;

printf("%d ", a);

next = a+b;

a = b;

b = next;

printf("\n");

int main () {

int n;

scanf("%d", &n);

ite(n);

printf("Fibonacci Series using Recursion is :\n");

for (int i = 0; i < n; i++) {

printf("%d ", fib(i));


}

return 0;

—-------------------------------------------------------------------------------------------------------------------

TASK 11Ai)

/*

Write a c program perform string reverse operation with and without using inbuilt function.

INPUT : ONE STRING S1

OUTPUT : AS PER TEST CASE FOTMAT

NOTE: USE THE STRREV FUNCTION PROVIDED IN REQUESTED FILE TO EXECUTE BUILT IN FUNCTION.

case=t3

input=GRIET

output=

STRING REVERSE

WITH UISNG STRING FUNCTIONS :s1 = TEIRG

WITHOUT UISNG STRING FUNCTIONS :s2 = TEIRG

*/

program:
#include <stdio.h>

#include<string.h>

char * strrev(char *str)

int i,len;
char temp;

len=strlen(str)-1;

for(i=0;i<strlen(str)/2;i++,len--)

temp=*(str+i);

*(str+i)=*(str+len);

*(str+len)=temp;

return(str);

int main()

char str[10], str1[10], str2[10], str3[10];

int len,i,j=0;

scanf("%s",str);

strcpy(str3,str);

strrev(str);

printf("\nSTRING REVERSE\n");

printf("WITH UISNG STRING FUNCTIONS :s1 = %s\n",str);

strcpy(str1,str3);

len = strlen(str1);

for(i=len-1;i>=0;i--)

str2[j]=str1[i];
j++;

str2[j]='\0';

printf("WITHOUT UISNG STRING FUNCTIONS :s2 = %s",str2);

—-------------------------------------------------------------------------------------------------------------------

TASK 11Aii)

/*

Write a c program perform string reverse operation with and without using inbuilt function.

INPUT : ONE STRING S1

OUTPUT : AS PER TEST CASE FOTMAT

NOTE: USE THE STRREV FUNCTION PROVIDED IN REQUESTED FILE TO EXECUTE BUILT IN FUNCTION.

case=t3

input=GRIET

output=

STRING REVERSE

WITH UISNG STRING FUNCTIONS :s1 = TEIRG

WITHOUT UISNG STRING FUNCTIONS :s2 = TEIRG

*/

program:
#include <stdio.h>

#include<string.h>

char * strrev(char *str)


{

int i,len;

char temp;

len=strlen(str)-1;

for(i=0;i<strlen(str)/2;i++,len--)

temp=*(str+i);

*(str+i)=*(str+len);

*(str+len)=temp;

return(str);

int main()

char str[10], str1[10], str2[10], str3[10];

int len,i,j=0;

scanf("%s",str);

strcpy(str3,str);

strrev(str);

printf("\nSTRING REVERSE\n");

printf("WITH USING STRING FUNCTIONS :s1 = %s\n",str);

strcpy(str1,str3);

len = strlen(str1);

for(i=len-1;i>=0;i--)
{

str2[j]=str1[i];

j++;

str2[j]='\0';

printf("WITHOUT USING STRING FUNCTIONS :s2 = %s",str2);

—-------------------------------------------------------------------------------------------------------------

TASK 11b)

/*

11b. Write a c program to check if given string is palindrome or not

Test cases:

input = madam

output = The entered string is palindrome

*/

//start program from next line......

program:
#include<stdio.h>

int main()

char str[10];

scanf("%s",str);

int i,l=0,flag=1,j;

for(i=0;str[i]!='\0';i++)
l++;

for(i=0,j=l-1;i<j;i++,j--)

if(str[i]!=str[j])

flag=0;

break;

if(flag==1)

printf("The entered string is palindrome");

else

printf("The entered string is not a palindrome");

return 0;

—-----------------------------------------------------------------------------------------------------------------------

TASK 11c)

/*

11c.Write a C program to sort the ‘n’ strings in the alphabetical order.

Test case:

input= 3

never

give
up

output =

THE ORIGINAL UNSORTED STRINGS ARE

1. never

2. give

3. up

THE SORTED STRINGS ARE:

1. give

2. never

3. up

*/

//start program from next line......

program:
#include<stdio.h>

#include<string.h>

#include<stdio.h>

int main()

char s[10][10],t[10];

int n,i,j;

scanf("%d",&n);

for(i=0;i<n;i++)

scanf("%s",s[i]);

printf("THE ORIGINAL UNSORTED STRINGS ARE\n");

for(i=0;i<n;i++)
printf("%d. %s\n",i+1,s[i]);

for(i=0;i<n;i++)

for(j=i+1;j<n;j++)

if(strcmp(s[i],s[j])>0)

strcpy(t,s[i]);

strcpy(s[i],s[j]);

strcpy(s[j],t);

printf("THE SORTED STRINGS ARE:\n");

for(i=0;i<n;i++)

printf("%d. %s\n",i+1,s[i]);

return 0;

—--------------------------------------------------------------------------------------------------------------------------------

TASK 12
/*
12a. Write a C program to implement function pointer to find sum and
product of two numbers.
Test Cases:
case = t4
input=
20 30
output=
SUM = 50
PRODUCT = 600

Input Format: Read the input


Output Format :Sum of numbers ,product of two numbers as shown in the
test case.
*/
//start program from next line......
PROGRAM
#include<stdio.h>
int sum(int a, int b)
{
return a+b;
}
int prod(int a,int b)
{
return a*b;
}
int main()
{
int a,b,x;
scanf("%d%d",&a,&b);
int (*fptr)(int a,int b);
fptr=sum;
x=fptr(a,b);
printf("SUM = %d",x);
fptr=prod;
x=fptr(a,b);
printf("\nPRODUCT = %d",x);
return 0;
}
—-----------------------------------------------------------------------------

/*

12b.Write a C program to sort list of numbers uing pointers.

Test Cases :

case = t2

Input=

3 0 1 4 7 6 -4 -45 10

output =

"UNSORTED LIST
3 0 1 4 7 6 -4 -45 10

Sorting Using Pointers

SORTED LIST

-45 -4 0 1 3 4 6 7 10 "

Input Format: Read the length "n" of the list and then read n number of integers.

Output Format :Print the unsorted list and the sorted list of numbers separated by spaces as shown in
the output.

*/

//start program from next line......

#include<stdio.h>

void sort(int *a,int);

void display(int *a,int n);

void main()

int i,n,a[20];

//printf("Enter size of the Array: ");

scanf("%d",&n);

//printf("\nEnter %d elements:\n",n);

for(i=0 ; i<n ; i++)

scanf("%d",&a[i]);

printf("UNSORTED LIST\n");

display(a,n);

sort(a,n);

printf("\nSorting Using Pointers");

printf("\nSORTED LIST\n");

display(a,n);

// function for sorting


void sort(int *a, int n)

int i,j,temp;

for(i=0;i<n-1;i++)

for(j=0;j<n-i-1;j++)

if(*(a+j)>*(a+j+1))

temp=*(a+j);

*(a+j)=*(a+j+1);

*(a+j+1)=temp;

//function for display

void display(int *a,int n)

int i;

for(i=0 ; i<n ; i++)

printf("%d ",*(a+i));

—--------------------------------------------------------------------------------------------------------

/*

LAB TASK 13a.

Define a structure Student, to store the following data about a student:

Rollno(int),name(string) and Marks(int).


Suppose that the class has ‘n’ students.

Use array of type Student and create a function to read the students data into the array.

Your program should be menu driven that contains the following options :

1.DisplayData 2.SearchByRollNo 3.Find Highest Score 4.exit

NOTE: CHECK FOR INVALID CHOICE ALSO.

INPUT FORMAT: READ "n" , then details of 'n' students name,rollno,marks.

Then read choice of operation - 1.DisplayData 2.SearchByRollNo 3.Find Highest Score 4.exit

Terminate the process with 4 to exit.(*last input)

NOTE : DEFINE AND USE THE FUNCTIONS AS GIVEN IN THE REQUESTED SOURCE FILE.

Test Cases :

Case = t2

input =

nayan 5 67

Kiran 9 87

2 10

29

output=

"

Student with Roll No 9 by Name Kiran got Maximum Marks 87

STUDENT DETAILS

Name RollNo Marks

nayan 5 67
Kiran 9 87

Student Data with Roll No 0 is not found.

Student Data with Roll No 9 found.

Name = Kiran and Marks = 87"

*/

//start program from next line......

#include <stdio.h>

#include<stdlib.h>

void ReadData();

void DisplayData();

void searchByRollNo(int);

void FindHighestScore();

int n;

struct student

char name[30];

int rollno;

int marks;

};

struct student s[10];

int main()

int ch,rno;

scanf("%d",&n);

ReadData();

while(1)

// printf("\n**MENU DRIVEN STUDENT DATA MANAGEMENT USING STRUCTURES***\n");


//printf("\n1.Create\n2.Display\n3.Search\n4.Find Highest Score\n5.exit\n");

// printf("enter your choice:");

scanf("%d",&ch);

switch(ch)

case 1:DisplayData();

break;

case 2://printf("enter the roll number of student to search:");

scanf("%d",&rno);

searchByRollNo(rno);

break;

case 3:FindHighestScore();

break;

case 4:exit(0);

default:printf("INVALID CHOICE");break;

return 0;

void ReadData()

int i;

//printf("Enter name, rollno and marks: \n");

for(i=0; i<n; i++)

//printf("enter student %d details:\n",i+1);

scanf("%s %d %d",s[i].name,&s[i].rollno,&s[i].marks);

}
void DisplayData()

int i;

printf("\nSTUDENT DETAILS\nName\tRollNo\tMarks");

for(i=0; i<n; i++)

printf("\n%-10s%-4d%4d",s[i].name,s[i].rollno,s[i].marks);

void searchByRollNo(int roll)

int i;

for (i=0; i<n; i++)

if(roll==s[i].rollno)

printf("\nStudent Data with Roll No %d found.\nName = %s and Marks =


%d",s[i].rollno,s[i].name,s[i].marks);

return;

printf("\nStudent Data with Roll No %d is not found.",s[i].rollno);

void FindHighestScore()

int i,maxindex,max=0;

for (i = 0; i <n; i++)

{
if (max < s[i].marks)

max = s[i].marks;

maxindex=i;

printf("\nStudent with Roll No %d by Name %s got Maximum Marks


%d",s[maxindex].rollno,s[maxindex].name,max);

—---------------------------------------------------------------------------------------------------------------

/*

13b.Write a C program that uses structures and functions to perform the following operations:

i. Addition of two complex numbers

ii. subtraction of two complex numbers

iii. Multiplication of two complex numbers

Test Cases :

Case = t1

Input =

23

45

output=

Complex Number C1:

2.00 + i 3.00

Complex Number C2:

4.00 + i 5.00

Sum of Complex Numbers C1 and C2:

6.00 + i 8.00
Difference of Complex Numbers C1 and C2:

-2.00 - i 2.00

Product of Complex Numbers C1 and C2:

-7.00 + i 22.00

Input Format: Read complex number c1 in first line (real and imaginary values)

read complex number c2 in second line.

Output Format: Display complex number C1 in first line.

Display complex number C2 in second line.

Display Sum, Difference and Product of Complex numbers C1 and C2 separated by new line.

*/

//start program from next line......

#include<stdio.h>

typedef struct

float rel;

float img;

}complex;

complex add(complex c1,complex c2);

complex subtract(complex c1,complex c2);

complex multiply(complex c1,complex c2);

void display(complex c);

void read(complex *c);

int main()

int i;

complex c1,c2,res;

//printf ("Enter Complex number 1: ");


read(&c1);

//printf ("Enter Complex number 2: ");

read(&c2);

printf("Complex Number c1:");

display(c1);

printf("\nComplex Number c2:");

display(c2);

res=add(c1,c2);

printf("\nSum of Complex Numbers C1 and C2:");

display(res);

res=subtract(c1,c2);

printf("\nDifference of Complex Numbers C1 and C2:");

display(res);

res=multiply(c1,c2);

printf("\nProduct of Complex Numbers C1 and C2:");

display(res);

return 0;

complex add(complex c1,complex c2)

complex c;

c.rel=c1.rel+c2.rel;

c.img=c1.img+c2.img;

return(c);

complex subtract(complex c1,complex c2)

complex c;
c.rel=c1.rel-c2.rel;

c.img=c1.img-c2.img;

return(c);

complex multiply(complex c1,complex c2)

complex c;

c.rel=c1.rel*c2.rel- c1.img*c2.img;

c.img=c1.rel*c2.img+c1.img*c2.rel;

return(c);

void display(complex c)

if(c.img<0)

printf("\n%.2f - i %.2f",c.rel,-c.img);

else

printf("\n%.2f + i %.2f",c.rel,c.img);

void read(complex *c)

//printf("\n Enter real part and imaginary part of complex number :");

scanf("%f %f",&c->rel,&c->img);

—------------------------------------------------------------------------------------------------------------------------------
TASK 14 & 15 CSE
/*

PPS LAB TASK 14 A

Write a C program to merge two files into a third file.

Test Cases :

case=t4

input=

file4.txt

file2.txt

output=

The contents of merged file are:

The world is so full

of a number of things,

I’m sure we should all

be as happy as kings.

THIS IS FCS LAB

LET'S START CODING.

Note:

The merged file name is "merge.txt"

Input files are already avilable - file1.txt,file2.txt,file3.txt,file4.txt.

Input Format: Read two file names as strings.

Output Format : Dsiplay the contents of the merged file.

*/

// Start Writing your program from here..!!

#include<stdio.h>

#include<stdlib.h>

int main( )
{

FILE *f1,*f2,*f3;

char ch,first[20],second[20];

scanf("%s %s",first,second);

f1=fopen(first,"r");

f2=fopen(second,"r");

if(f1==NULL||f2==NULL)

printf("Cannot open - File does not exist.");

return 0;

f3=fopen("merge.txt","w");

while((ch=getc(f1))!=EOF)

putc(ch,f3);

fclose(f1);

while((ch=getc(f2))!=EOF)

putc(ch,f3);

fclose(f3);

fclose(f2);

printf("The contents of merged file are:\n");

f3=fopen("merge.txt","r");

while((ch=getc(f3))!=EOF)

putchar(ch);

fclose(f3);

return 0;
}

—------------------------------------------------------------------------------------------------------------------------

/*

PPSL TASK 14 B

Write a C program to count number of characters in a file and also convert all lower case

characters to upper case and display it

Test Cases :

case = t1

input= f1.txt

output=

#INCLUDE <STDIO.H>

INT MAIN()

PRINTF("HELLO WORLD");

RETURN 0;

Number of characters = 73.

Note:TO RUN YOU CAN USE THE ALREADY EXISTING FILES f1.txt,f2.txt.

INPUT FORMAT: READ FILE NAME AS A STRING FROM USER.

OUTPUT FORMAT: DISPLAY THE OUTPUT AS PER THE GIVEN TEST CASE FORMAT.

*/

// Start Writing your program from here..!!

#include<stdio.h>

#include<stdlib.h>

#include<ctype.h>

int main()
{

FILE *fptr;

char ch,fname[20];

int count=0;

scanf("%s",fname);

fptr = fopen(fname,"r");

if(fptr==NULL)

printf("Cannont open - File does not exist.");

return 0;

while((ch=fgetc(fptr))!=EOF)

putchar(toupper(ch));

count++;

fclose(fptr);

printf("\nNumber of characters = %d.",count);

return 0;

—------------------------------------------------------------------------------------------------------------------

/*

PPS LAB TASK 14 C

Write a C program to append a file and display it.

Test Cases :

case = t1

input=

test1.txt
The above function is a non recursive Fibonacci series function.

Now you try to wite a recursive Fibonacci series function.@

output=

"The Contents of Appended file are :

void ITER_FIB(int a,int b,int n)

int i,c;

for(i=1;i<=n;i++)

c=a+b;

printf(" %d",c);

a=b;

b=c;

The above function is a non recursive Fibonacci series function.

Now you try to wite a recursive Fibonacci series function."

Note: USE THE EXISTING FILE test1.txt,test2.txt

INPUT FORMAT : READ SOME TEXT THROUGH CONSOLE AND TERMINATE WITH @

SO USE while((ch=getchar())!='@')

OUTPUT FORMAT : DISPLAY THE CONTENTS OF THE APPENDED FILE AS PER TEST CASE.

*/

// Start Writing your program from here..!!

#include<stdio.h>

int main()

FILE *fp;

char ch,fname[20];
scanf("%s",fname);

fp=fopen(fname,"a+");

while((ch=getchar())!='@')

fputc(ch,fp);

rewind(fp);

printf("The Contents of Appended file are :\n");

while ((ch=fgetc(fp))!= EOF)

printf ("%c", ch);

fclose(fp);

return 0;

—---------------------------------------------------------------------------------------------------------------------------

/*Write a c program to find sum of n numbers using command line arguments.

Test case:

Case = t3

Program Arguments = 1 2 3 4 5 6 7

output =

"The sum of 7 numbers using command line arguments = 28"

NOTE: ONLY EVALUATE THE PROGRAM DO NOT RUN.

Input: ALREADY GIVEN THROUGH COMMAND LINE, USE THEM ACCORDINGLY.

output: DISPLAY THE OUTPUT AS PER THE TEST CASE

*/
#include<stdio.h>

#include<stdlib.h>

int main(int argc, char *argv[])

int a,b,sum=0,i;

if(argc<2)

printf("Insufficient Arguments.");

return -1;

for(i=1; i<argc; i++)

sum += atoi(argv[i]);

printf("The sum of %d numbers using command line arguments = %d",argc-1,sum);

return 0;

—------------------------------------------------------------------------------------------------------------------

/*

FCSL LAB ATSK 8A

8 a) Write a c program to implement following pre-processor directives.

(i) define (ii) ifdef (iii) undef (iv) ifndef.

Note: Define PI as with constant value 3.142

Also define MAX with a Value 100.

Develop a menu driven (switch case) program.

choice: 1.define 2.ifdef 3.undef 4.ifndef

Follow the below points:


For define use PI and calculate area and circumferenec of a Circle.

For undef Firstly define x with 10 and redine x to 20 after undef.

For ifdef Test if MAX is defined if so display its value otherwise print not defined.

For ifndef Test if MIN is not defined if so display not defined otherwise MIN value.

Test Cases :

Case = t1

input=

output=

"USING #DEFINE

Area of Circle with radius 4 Units = 50.27 Square Units.

Circumference of Circle = 25.14 Units."

Case = t3

input=

output=

"USING DEFINE X = 10

USING #UNDEF and again defining X

AFTER UNDEF AND DEFINE X = 20"

Input Format: Read radius as an integer value.

Output Format :Dispaly as per test case format.

*/

// Start Writing your program from here..!!


#include<stdio.h>

#define PI 3.142

#define MAX 100

#define X 10

int main()

int ch,r;

scanf("%d",&ch);

switch(ch)

case 1: scanf("%d",&r);

float cir=2*PI*r;

float ar=PI*r*r;

printf("USING #DEFINE");

printf("\nArea of Circle with radius %d Units = %.2f Square Units.",r,ar);

printf("\nCircumference of Circle = %.2f Units.",cir);

break;

case 2: printf("TEST MAX BY UISNG #IFDEF");

#ifdef MAX

printf("\nMAX IS DEFINED AND MAX VALUE = %d",MAX);

#else

printf("\nMAX IS NOT DEFINED");

#endif

break;

case 3: printf("USING DEFINE X = %d",X);

printf("\nUSING #UNDEF and again defining X");

#undef X

#define X 20
printf("\nAFTER UNDEF AND DEFINE X = %d",X);

break;

case 4: printf("TEST BY UISNG #IFNDEF");

#ifndef MIN

printf("\nMIN IS NOT DEFINED");

#else

printf("\nMIN IS DEFINED AND MIN VALUE = %d",MIN);

#endif

break;

default:printf("Invalid Choice.");

break;

return 0;

—-----------------------------------------------------------------------------------------------------------------------------

/*

LAB TASK 15C

Write a c program to create a user defined header file to find sum, product and greatest of

two numbers

Test Cases :

Case = t1

input=30 50

output=

"Sum of 30 and 50 = 80

Product of 30 and 50 = 150

Maximum of 30 and 50 = 50"


Input Format: Read two integer numbers

Output Format :Sum, Product and Maximum of 2 numbers displayed in separate lines.

Note: Students need to include the myheader.h header file in their program.

myheader.h contains the following function descriptions:

int FindSum(int p,int q);

int FindProduct( int a,int b);

void FindMax(int a,int b);

*/

// Start Writing your program from here..!!

// program gr22a15c.c

#include<stdio.h>

#include"myheader.h"

int main()

int a,b,res;

//printf("\n Enter values for a,b :");

scanf("%d%d",&a,&b);

printf("Sum of %d and %d = %d",a,b,FindSum(a,b));

res=FindProduct(a,b);

printf("\nProduct of %d and %d = %d",a,b,res);

FindMax(a,b);

return 0;

You might also like