PPS LAB PROGRAMS
PPS LAB PROGRAMS
/*
QUESTION:
1a. Write a C program to convert days into years, weeks and days.(Assume a year has 365 days)
Case=t4
Input= 1238
Output=
*/
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;
return 0;
--------------------------------------------------------------------------------------------------------------------------
/*
QUESTION
1b. Write a C program to find greatest and smallest among three numbers using conditional operator.
INPUT: 3 INTEGERS
Test cases:
Case=t3
Input=
Output=
*/
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);
return 0;
}
/*
QUESTION:
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=
*/
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)));
return 0;
/*
QUESTION
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=
*/
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;
return 0;
/*
2B (i,ii) Write a C program to do the following using implicit and explicit type conversion
TEST CASE:
case=t6
input=
5.6 18.8
output=
OUTPUT FORMAT: DISPALY THE FARENHEIT AND CELCIUS TEMPERATURES IN GIVEN TEST CASE FORMAT
UPTO ONE DECIMAL POINTS.
*/
program:
#include<stdio.h>
int main()
float a,c,b,d;
scanf("%f",&a);
b=(float)5/9*(a-32);
scanf("%f",&c);
d=(float)9/5*c+32;
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
OUTPUT FORMAT: DISPLAY AREA(DOUBLE TYPE) UPTO TWO DECIMAL VALUES AS PER TEST CASE
Test cases:
Case=t2
Input=12 10 8
Output=
*/
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));
return 0;
/*
3a. Write a C program to add two numbers without using arithmetic operators in C.
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
*/
program:
#include<stdio.h>
int main()
int a,b,d;
scanf("%d%d",&a,&b);
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.
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
*/
program:
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
return 0;
/*
3c. Write a C program to check whether a number is even or odd using bitwise operator and ternary
operator.
Test Cases:
Case=t1
Input=4
Output=
4 is an Even Number.
Case=t2
Input=21
Output=
21 is an Odd Number.
*/
program:
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
return 0;
/*
4a. Write a C program to find the roots of a quadratic equation using if-else.
Test Cases:
case=t1
Input = 1 -8 -6
Output =
Root 1 = 8.690
Root 2 = -0.690
*/
#include <stdio.h>
int main()
d = b * b - 4 * a * c;
if (d > 0)
else if (d == 0)
else
realPart = -b / (2 * a);
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:
Test Cases:
case=t1
input=50
output=
*/
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);
return 0;
//cost+cost*((float)20/100)
/*
QUESTION:
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
*/
program:
#include<stdio.h>
int main()
int choice,a,b;
scanf("%d%d%d",&choice,&a,&b);
switch(choice){
break;
break;
break;
break;
case 4 : if(b==0)
else
break;
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
*/
program:
#include<stdio.h>
int main()
int choice;
scanf("%d",&choice);
switch(choice)
break;
case 2: printf("February 28 days");
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
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=
case=t5
input=
10
output=
*/
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)
else
/*
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=
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
return 0;
}
/*
5c. Write a C Program check whether a given number is Armstrong number or not.
Test Cases:
case=t1
input=
371
output=
case=t2
input=
111
output=
*/
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)
else
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=
*/
program:
#include<stdio.h>
#include<stdlib.h>
int main()
scanf("%d",&num);
n = num;
if(n==0)
exit(0);
while(num > 0)
fact = 1;
fact = fact*i;
}
if(n<0)
printf("Invalid Input");
else if(sum==n)
else
return 0;
/*
i) ****
* *
* *
****
Test Cases:
case=t1
input=5
output=
*****
* *
* *
* *
*****
*/
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;
/*
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
*/
program:
#include <stdio.h>
int main() {
int n, i, j, k,c = 1;
scanf("%d", &n);
printf(" ");
for(k=1;k<=i;k++)
printf("%d ",c);
c++;
}
printf("\n");
return 0;
/*
iii) 1
22
333
4444
Test Cases:
case=t1
input=3
output=
22
333
*/
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=
1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097
OUTPUT FORMAT:DISPLAY THE PRIME NUMBERS SEPERATED WITH A SPACE AS PER TEST CASE FORMAT
*/
program:
#include<stdio.h>
int main()
int n,m,i,j,c;
scanf("%d%d",&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;
/*
Test Cases:
case=t3
input= -1 3
output=
SUM = -0.666667
case=t4
input= 1 3
output=
SUM = 1.666667
OUTPUT FORMAT: DISPLAY SUM AS PER THE GIVEN TEST CASE FORMAT
*/
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:
TEST CASE:
case=t2
input= 4 5
output=
case=t3
input= -2 3
output=
*/
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
Case = t2
Input = 5
9 6 90 123 65
Output =
SUM = 293
AVERAGE = 58.60
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.
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]);
sum+=a[i];
printf("SUM = %d\n",sum);
avg = (float)sum/n;
printf("AVERAGE = %.2f\n",avg);
if(a[i]<min)
min = a[i];
l1 = i;
{
if(a[i]>max)
max = a[i];
l2 = i;
return 0;
/*
TEST CASE:
Case = t1
input = 4
109 56 167 67
100
output =
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,
Output Format : The output is search successful element found at particular position based on search
key.
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])
break;
if(i==n)
return 0;
}
/*
Test Cases :
Case = t2
input = 5
10 20 30 40 50
20
output =
Case = t3
input = 5
10 45 67 89 100
89
output =
Input Format: Read the number of elements in array in first line, Enter the elements in second line
separated by space,
Output Format : The output is search successful element found at particular position based on search
key.
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)
break;
else
high=mid-1;
mid=(low+high)/2;
if(low>high)
return 0;
}
Case = t3
Input = 2 3 2 3
123456
123456
output =
SUM MATRIX C
2 4 6
8 10 12
Case = t4
Input = 2 3 3 3
output =
Input Format: Read the order of both the matrices in first line.
Output Format :Print the resultant matrix is or print Matrix Addition is not possible as shown in the test
case.
*/
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];
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
/*
Test Cases :
Case = t3
Input = 2 3 3 2
123456
123456
output =
PRODUCT MATRIX C
22 28
49 64
Case = t4
Input = 3 2 3 2
output =
Input Format: Read the input matrix as integer based on dimensions. (first line the number of elements
in matrix, second line first matrix elements
Output Format :print resultant matrix is or print multiplication is not possible if matrix dimension is not
same.
*/
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){
scanf("%d",&a[i][j]);
scanf("%d",&b[i][j]);
c[i][j] = 0;
c[i][j]+=a[i][k]*b[k][j];
printf("%d\t",c[i][j]);
printf("\n");
}else{
return 0;
/*
9a. Write a C program to display binary equivalent of a given decimal number using functions
Test cases:
case=t1
Input =34
*/
program:
#include<stdio.h>
long toBin(int);
int main()
long bno;
int dno;
scanf("%d",&dno);
bno=toBin(dno);
return 0;
long bno=0,remainder,f=1;
while(dno!=0)
{
remainder=dno%2;
bno=bno+remainder*f;
f=f*10;
dno=dno/2;
return bno;
—---------------------------------------------------------------------------------------------------------------------
/*
Test cases:
case=t1
Input =2 2
1265
output =
Original Matrix
1 2
6 5
Transpose Matrix
1 6
2 5
*/
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=
*/
program:
#include <stdio.h>
#include <string.h>
{
if(strcmp(s1,s2)==0)
else
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 =
*/
program:
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
if(n<0)
printf("Invalid Input");
else
return 0;
if(n==0)
return 1;
else
return(n*Recursion(n-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=
*/
program:
#include<stdio.h>
{
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;
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);
y=gdcr(n,m);
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=
*/
program:
#include <stdio.h>
int fib(int n)
if (n <= 1 ) return n;
void ite(int n) {
int a = 0, b = 1;
int next;
next = a+b;
a = b;
b = next;
printf("\n");
int main () {
int n;
scanf("%d", &n);
ite(n);
return 0;
—-------------------------------------------------------------------------------------------------------------------
TASK 11Ai)
/*
Write a c program perform string reverse operation with and without using inbuilt function.
NOTE: USE THE STRREV FUNCTION PROVIDED IN REQUESTED FILE TO EXECUTE BUILT IN FUNCTION.
case=t3
input=GRIET
output=
STRING REVERSE
*/
program:
#include <stdio.h>
#include<string.h>
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()
int len,i,j=0;
scanf("%s",str);
strcpy(str3,str);
strrev(str);
printf("\nSTRING REVERSE\n");
strcpy(str1,str3);
len = strlen(str1);
for(i=len-1;i>=0;i--)
str2[j]=str1[i];
j++;
str2[j]='\0';
—-------------------------------------------------------------------------------------------------------------------
TASK 11Aii)
/*
Write a c program perform string reverse operation with and without using inbuilt function.
NOTE: USE THE STRREV FUNCTION PROVIDED IN REQUESTED FILE TO EXECUTE BUILT IN FUNCTION.
case=t3
input=GRIET
output=
STRING REVERSE
*/
program:
#include <stdio.h>
#include<string.h>
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()
int len,i,j=0;
scanf("%s",str);
strcpy(str3,str);
strrev(str);
printf("\nSTRING REVERSE\n");
strcpy(str1,str3);
len = strlen(str1);
for(i=len-1;i>=0;i--)
{
str2[j]=str1[i];
j++;
str2[j]='\0';
—-------------------------------------------------------------------------------------------------------------
TASK 11b)
/*
Test cases:
input = madam
*/
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)
else
return 0;
—-----------------------------------------------------------------------------------------------------------------------
TASK 11c)
/*
Test case:
input= 3
never
give
up
output =
1. never
2. give
3. up
1. give
2. never
3. up
*/
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]);
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);
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
/*
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
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.
*/
#include<stdio.h>
void main()
int i,n,a[20];
scanf("%d",&n);
//printf("\nEnter %d elements:\n",n);
scanf("%d",&a[i]);
printf("UNSORTED LIST\n");
display(a,n);
sort(a,n);
printf("\nSORTED LIST\n");
display(a,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;
int i;
printf("%d ",*(a+i));
—--------------------------------------------------------------------------------------------------------
/*
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 :
Then read choice of operation - 1.DisplayData 2.SearchByRollNo 3.Find Highest Score 4.exit
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 DETAILS
nayan 5 67
Kiran 9 87
*/
#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;
};
int main()
int ch,rno;
scanf("%d",&n);
ReadData();
while(1)
scanf("%d",&ch);
switch(ch)
case 1:DisplayData();
break;
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;
scanf("%s %d %d",s[i].name,&s[i].rollno,&s[i].marks);
}
void DisplayData()
int i;
printf("\nSTUDENT DETAILS\nName\tRollNo\tMarks");
printf("\n%-10s%-4d%4d",s[i].name,s[i].rollno,s[i].marks);
int i;
if(roll==s[i].rollno)
return;
void FindHighestScore()
int i,maxindex,max=0;
{
if (max < s[i].marks)
max = s[i].marks;
maxindex=i;
—---------------------------------------------------------------------------------------------------------------
/*
13b.Write a C program that uses structures and functions to perform the following operations:
Test Cases :
Case = t1
Input =
23
45
output=
2.00 + i 3.00
4.00 + i 5.00
6.00 + i 8.00
Difference of Complex Numbers C1 and C2:
-2.00 - i 2.00
-7.00 + i 22.00
Input Format: Read complex number c1 in first line (real and imaginary values)
Display Sum, Difference and Product of Complex numbers C1 and C2 separated by new line.
*/
#include<stdio.h>
typedef struct
float rel;
float img;
}complex;
int main()
int i;
complex c1,c2,res;
read(&c2);
display(c1);
display(c2);
res=add(c1,c2);
display(res);
res=subtract(c1,c2);
display(res);
res=multiply(c1,c2);
display(res);
return 0;
complex c;
c.rel=c1.rel+c2.rel;
c.img=c1.img+c2.img;
return(c);
complex c;
c.rel=c1.rel-c2.rel;
c.img=c1.img-c2.img;
return(c);
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);
//printf("\n Enter real part and imaginary part of complex number :");
scanf("%f %f",&c->rel,&c->img);
—------------------------------------------------------------------------------------------------------------------------------
TASK 14 & 15 CSE
/*
Test Cases :
case=t4
input=
file4.txt
file2.txt
output=
of a number of things,
be as happy as kings.
Note:
*/
#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)
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);
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
Test Cases :
case = t1
input= f1.txt
output=
#INCLUDE <STDIO.H>
INT MAIN()
PRINTF("HELLO WORLD");
RETURN 0;
Note:TO RUN YOU CAN USE THE ALREADY EXISTING FILES f1.txt,f2.txt.
OUTPUT FORMAT: DISPLAY THE OUTPUT AS PER THE GIVEN TEST CASE FORMAT.
*/
#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)
return 0;
while((ch=fgetc(fptr))!=EOF)
putchar(toupper(ch));
count++;
fclose(fptr);
return 0;
—------------------------------------------------------------------------------------------------------------------
/*
Test Cases :
case = t1
input=
test1.txt
The above function is a non recursive Fibonacci series function.
output=
int i,c;
for(i=1;i<=n;i++)
c=a+b;
printf(" %d",c);
a=b;
b=c;
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.
*/
#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);
fclose(fp);
return 0;
—---------------------------------------------------------------------------------------------------------------------------
Test case:
Case = t3
Program Arguments = 1 2 3 4 5 6 7
output =
*/
#include<stdio.h>
#include<stdlib.h>
int a,b,sum=0,i;
if(argc<2)
printf("Insufficient Arguments.");
return -1;
sum += atoi(argv[i]);
return 0;
—------------------------------------------------------------------------------------------------------------------
/*
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
Case = t3
input=
output=
"USING DEFINE X = 10
*/
#define PI 3.142
#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");
break;
#ifdef MAX
#else
#endif
break;
#undef X
#define X 20
printf("\nAFTER UNDEF AND DEFINE X = %d",X);
break;
#ifndef MIN
#else
#endif
break;
default:printf("Invalid Choice.");
break;
return 0;
—-----------------------------------------------------------------------------------------------------------------------------
/*
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
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.
*/
// program gr22a15c.c
#include<stdio.h>
#include"myheader.h"
int main()
int a,b,res;
scanf("%d%d",&a,&b);
res=FindProduct(a,b);
FindMax(a,b);
return 0;