0% found this document useful (0 votes)
73 views38 pages

Problem Solving Techniques Lab Manual-1

The document provides details about a lab manual for the course "Problem Solving Techniques Lab" with course code MCAS1171. It includes the vision, mission, program educational objectives, program outcomes, and program specific outcomes of the School of Computing Science and Engineering. It also lists 20 programs that students will write as part of the lab assignments and provides sample code for 3 programs - to convert temperature from Celsius to Fahrenheit, to perform basic math operations using a switch statement, and to swap the values of two variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views38 pages

Problem Solving Techniques Lab Manual-1

The document provides details about a lab manual for the course "Problem Solving Techniques Lab" with course code MCAS1171. It includes the vision, mission, program educational objectives, program outcomes, and program specific outcomes of the School of Computing Science and Engineering. It also lists 20 programs that students will write as part of the lab assignments and provides sample code for 3 programs - to convert temperature from Celsius to Fahrenheit, to perform basic math operations using a switch statement, and to swap the values of two variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 38

FALL Semester 2020-2021

Lab Manual

Date:

This document gives specific details regarding the Lab

Course Code : MCAS1171


Course Title : Problem Solving Techniques Lab

Vision of the School of computing science and Engineering:

To be recognized globally as a premier school of Computing Science and Engineering for


imparting quality and value based education engaged in multi-disciplinary and collaborative
research.

Mission of the School of computing science and Engineering:

M1: Developing a strong foundation in fundamentals of computing science with responsiveness


towards emerging technologies.

M2: Establishing state-of-the-art facilities and adopt education 4.0 practices to analyse, develop,
test and deploy sustainable ethical IT solutions by involving multiple stakeholders.

M3: Establishing Centres of Excellence for multidisciplinary collaborative research in


association with industry and academia.

Programme educational objectives(PEOs):

The Graduates of Computer Application and Information Science shall:

PEO1: Be engaged with leading Global Software Services and Product development companies
handling projects in cutting edge technologies
PEO2: Engaged in technical or managerial roles at Government firms, Corporates, Start-ups or
contribute to the society as successful entrepreneurs.

PEO3: Undertake higher education, research or academia at institutions of transnational


reputation.

Programme outcomes:

PO1:Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
PO11: Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change

Programme specifics outcome(PSO):

PSO1: Ability to work with emerging technologies in computing requisite to Industry 4.0
PSO2: Demonstrate Computing science Practice learned through industry internship to solve
live problems in various domains.

COs :students will be able to:

CO1: Identify appropriate algorithms and apply C language syntax for solving practical
problems
CO2: Convert problem solving strategies into C programs
CO3: Analyse result and interpret data.
CO4: Write C program and represent result
CO5: Execute C program and organize lab report

CO-PO mapping

COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2

CO1 2 2 1

CO2 2 2 1

CO3 2 2 1

CO4 2 2 1

CO5 2 2 1

CO6 2 2 1

Evaluation Scheme:
Rubrics for Each Evaluation Scheme:
List of Programs:

1. Write a program to convert temperature from degree centigrade to


Fahrenheit. °F = °C*9/5+32

2. Write a program to compute the addition, subtraction, product, quotient and remainder
of two given numbers.

3. Write a program to swap the values of two variables.

4. Write a program to compute net amount from the given quantity purchased and
rate per quantity. Discount of 10 .is allowed if quantity purchased exceeds 100.

5. Write a program to print the sum of digit of a given number.

6. Write program to print the Fibonacci series up to a given number.

7. Write a program to print the prime numbers within a given number.

8. Write a program to check a given number is prime or not.


9. Write a program to check whether a no is an Armstrong number.

10. Write a program to determine and print the sum of the following harmonic series for a
given value of n =1 +1/2+1/3+1/4+……+1/n

11. Write a program to print the Floyds triangle

1
23
456
12. Write a program to read three integer values from the keyboard and display the output
stating that they are the sides of right angled triangle.

13. Write a program to accept an year from the user and check whether the entered year is
a leap year or not.

14. Write a program to print binary equivalent of an integer number.

15. Write a program to print the following pattern (take number of lines as input from the
user).

***
**
*
16. Write a program to find out the length of a given string without using the library
function strlen().

17. Write a program to print the reverse of a given string.

18. Write a program to check if a given string is palindrome or not. A string is said to
be palindrome if the reverse of the string is equal to the string.

19. Write a program to count the number of vowels in a given string.

20. Write a program for addition of two nxm matrices


21. Write a program for multiplication of two nxm matrics

22. Write a program to compute factorial of a given number using function.

23. Write a function for swapping of two numbers.

24. Write a program for finding factorial of a number using recursion.

25. Write a program to sort an array using Bubble Sort (using function).

26. Write a program to search a key number in an array using Sequential Search Method.
(use function)
27. Write a program to accept student details (name,Enroll No, address, phone no,
Email)and store them in a file and perform the following operations on it.

a. Search b. Add c. Delete d. Modify e. Display.

PROGRAM 1:WRITE A PROGRAM TO CONVERT TEMPERATURE FROM CENTIGRADE TO


FAHRENHEIT.F=C*(9/5)+32*/

#include <stdio.h>

float tempchange(int c)

float f;

f=c*1.8+32;

return f;

int main()

int c;float f;

printf("enter the temperature in centigrade:");

scanf("%d",&c);

f=tempchange(c);

printf("Fahrenheit:%5.2f",f);

return 0;

OUTPUT:-

enter the temperature in centigrade:37

Fahrenheit:98.60

PROGRAM 2:WRITE A PROGRAM TO PERFORM ADDITION SUBTRACTION MULTIPLICATION


DIVISION AND POWER USING SWITCH*/

#include <stdio.h>
#include <conio.h>

#include <math.h>

void main()

printf("enter 2 numbers:");

int a,b,ch,c;

scanf("%d",&a);

scanf("%d",&b);

printf("enter the opertion to be performed:");

printf("1.Addition\n");

printf("2.Substraction\n");

printf("3.Multiplication\n");

printf("4.division\n");

printf("5.Power\n");

printf("6.Exit\n");

scanf("%d",&ch);

switch(ch)

case 1:c=a+b;

printf("%d+%d=%d",a,b,c);break;

case 2:c=a-b;

printf("%d-%d=%d",a,b,c);break;

case 3:c=a*b;

printf("%dX%d=%d",a,b,c);break;

case 4:c=a%b;

printf("%d/%d=%d",a,b,c);break;

case 5:c=pow(a,b);

printf("%d to the power %d=%d",a,b,c);break;

case 6:break;

default:printf("invalid input");
}

getch();

OUTPUT:-

enter 2 numbers:23

43

enter the opertion to be performed:1.Addition

2.Substraction

3.Multiplication

4.division

5.Power

6.Exit

23+43=66

PROGRAM 3:WRITE A PROGRAM TO SWAP VALUES OF TWO VARIABLES*/

#include <stdio.h>

#include <conio.h>

#include <math.h>

void swap(int a,int b)

int c=a;

a=b;

b=c;

printf("Swapped numbers are %d and %d",a,b);

int main()

int a,b;

printf("enter two numbers:");


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

swap(a,b);

OUTPUT:-

enter two numbers:23

45

Swapped numbers are 45 and 23

PROGRAM 4:WRITE A PROGRAM TO COMPUTE NET AMOUNT FROM THE GIVEN QUENTITY
PURCHASED AND RATE PER QUANTITY. DISCOUNT OF 10 IS ALLOWED IF QUANTITY
PURCHASED AND RATE PER QUATITY PURCHASED EXCEEDS 100*/

#include <stdio.h>

int main()

int pa;

int d;

int na;

printf("enter the purchased amount:");

scanf("%d",&pa);

if(pa<100)

na=pa;

else

na=pa-10;

printf("net amount:%d",na);

OUTPUT:-

enter the purchased amount:567

net amount:557

PROGRAM 5 :WRITE A PROGRAM TO PRINT SUM OF DIGITS OF A GIVEN NUMBER*/


#include <stdio.h>

int main()

int n,b=0,t;

printf("enter a number:");

scanf("%d",&n);

while(n>0)

t=n%10;

b=b+t;

n=n/10;

printf("\nsum:-%d",b);

OUTPUT:-

enter a number:345

sum:-12

PROGRAM 6 :WRITE A PROGRAM IN C TO PRINT FIBONACCI SERIES*/

#include <stdio.h>

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

int c;

if(n>0)

c=a+b;

printf("%d,",c);

fibo(b,c,n-1);

main()
{

int n;int a=0,b=1;int c;

printf("enter the number:");

scanf("%d",&n);

printf("0,1,");

fibo(a,b,n-2);

OUTPUT:-

enter the number:6

0,1,1,2,3,5,

PROGRAM 7:WRITE A PROGRAM TO PRIME NUMBER WITHIN A GIVEN NUMBER


FUNCTION(RETUTRN TYPE)*/

#include <stdio.h>

#include <conio.h>

int prime(int a)

int i;int c=0;

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

if(a%i==0)

c++;

if(c==2)

return 1;

else

return 0;

int main()

int n,i;

printf("enter the nth number:");


scanf("%d",&n);

printf("prime numbers are:\n");

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

int t=prime(i);

if(t==1)

printf("%d\n",i);

OUTPUT:-

enter the nth number:10

prime numbers are:

PROGRAM 8:WRITE A PROGRAM TO PRIME NUMBER UPTO N USING FUNCTION(RETUTRN


TYPE)*/

#include <stdio.h>

#include <conio.h>

void main()

int a;

int i;int c=0;

printf("enter a number:");

scanf("%d",&a);

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

if(a%i==0)
c++;

if(c==2)

printf("%d is a prime",a);

else

printf("%d is not a prime",a);

OUTPUT:-

enter a number:97

97 is a prime

PROGRAM 9:WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS AN ARMSTRONG OR


NOT*/

#include<stdio.h>

#include<math.h>

int armstrong(int n)

int t,b;

while(n>0)

t=n%10;

b=b+pow(t,3);

n=n/10;

return b;

int main()

int n,n1;

printf("enter a number:");

scanf("%d",&n);

n1=armstrong(n);
if(n==n1)

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

else

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

return 0;

OUTPUT:-

enter a number:153

153 is a armstrong number

PROGRAM 10:WRITE A PROGRAM TO WHICH PRINT RESULT OF SERIES:

1+1/2+1/3+.........1/N */

#include <stdio.h>

#include <conio.h>

#include <math.h>

void main()

int n;float sum=0;float a;

printf("enter the value of n:");

scanf("%d",&n);

int i;

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

printf("1/%d+",i);

a=(float)1/(float)i;

sum=sum+a;

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

}
OUTPUT:

enter the value of n:12

1/1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+=3.10

PROGRAM 11:WRITE A PROGRAM TO PRINT FLOYDS TRIANGLE*/

#include<stdio.h>

int main()

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

printf("enter the value of n:");

scanf("%d",&n);

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

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

printf("%d",c++);

printf("\n");

OUTPUT:-

enter the value of n:4

23

456

78910

PROGRAM 12:WRITE A PROGRAM TO READ THREE INTEGERS VALUES FROM KEYBOARD


AND DISPLAY THE OUTPUT STATING THAT THEWY ARE THE SIDE OF RIGHT ANGLED
TRIANGLE*/

#include<stdio.h>

int main()

int a,b,c;int check=0;

printf("enter three sides of a triangle:");


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

if((a*a+b*b)==(c*c))

check=1;

if((b*b+c*c)==(a*a))

check=1;

if((a*a+c*c)==(b*b))

check=1;

if(check==1)

printf("the sides are of a right angled triangle");

else

printf("the sides are not of a right angled triangle");

OUTPUT:-

enter three sides of a triangle:5

the sides are of a right angled triangle

PROGRAM 13:WRITE A PROGRAM TO ACCEPT AN YEAR FROM THE USER AND CHEACK
WHETHER THE ENTERED YEAR IS A LEAP YEAR OR NOT*/

#include <stdio.h>

int main()

int year;

printf("Enter a year: ");

scanf("%d",&year);

if(year%4 == 0)

if( year%100 == 0)

if ( year%400 == 0)

printf("%d is a leap year.", year);


else

printf("%d is not a leap year.", year);

else

printf("%d is a leap year.", year );

else

printf("%d is not a leap year.", year);

return 0;

OUTPUT:-

Enter a year: 2016

2016 is a leap year.

PROGRAM 14 :WRITE A PROGRAM TO CONVERT DECIMAL TO ITS BINARY FORM*/

#include <stdio.h>

#include <conio.h>

#include <math.h.>

int octal(int d)

int i=0,b=0;

while(d!=0)

int r=d%2;

b=b+r*pow(10,i);

d=d/2;i++;

return b;

void main()
{

int n;

printf("enter a decimal number:");

scanf("%d",&n);

int oct=octal(n);

printf("BINARY equivalent:%d\n",oct);

OUTPUT:

enter a decimal number:56

BINARY equivalent:111000

PROGRAM 15:WRITE A PROGRAM TO PRINT PATTERN(TAKE NUMBER OF LINES AS INPUT


FREM THE USER)*/

#include<stdio.h>

int main()

int n,i,j;

printf("enter the value of n:");

scanf("%d",&n);

for(i=n;i>=1;i--)

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

printf("*");

printf("\n");}

OUTPUT:-

enter the value of n:7

*******

******

*****

****

***
**

PROGRAM 16 :WRITE A PROGRAM IN TO FIND OUT THE LENGTH OF A GIVEN STRING


WITHOUT USING THE LIBRARY FUNCTION strlen()*/

#include<stdio.h>

#include<string.h>

#define size 100

int sizecheck(char name[size])

int i,c=0;

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

if(name[i] == '\0')

break;

return i;

void main()

int s;

char name[size];

gets(name);

s=sizecheck(name);

printf("size of the string=%d",s);

OUTPUT:-

gaLGOtias UNIVERSITY

size of the string=20

PROGRAM 17 :WRITE A PROGRAM PRINT REVERSE OF A GIVEN STRING*/

#include<stdio.h>
#include<string.h>

#define size 100

void output(char name[size],int l)

int i;

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

printf("%c",name[i]);

void reverse(char name[size],int l)

char name1[l];

int i,c=0;

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

name1[c++]=name[i];

output(name1,l);

int main()

{ int s,l;

char name[size];

printf("enter a string:");

gets(name);

l=strlen(name);

printf("reversed string are:");

reverse(name,l);

OUTPUT:-
enter a string:ABHIMANYU

reversed string are:UYNAMIHBA

PROGRAM 18:WRITE A PROGRAM IN C USING FUNCTION TO CHECK WHETHER IS STRING IS


PALINDROME OR NOT. A STRING IS A PALINDROME IF THE REVERSE OF THE STRING IS
EQUAL TO THE STRING.*/

#include<stdio.h>

#include<string.h>

#define size 100

void output(char name[size],int l)

int i;

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

printf("%c",name[i]);

void reverse(char name[size],int l)

char name1[l];

int i,c=0;

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

name1[c++]=name[i];

output(name1,l);

if(strcmp(name,name1)==0)

printf("\nPalindrome String");

int main()
{

int s,l;

char name[size];

printf("enter a string:");

gets(name);

l=strlen(name);

printf("reversed string are:");

reverse(name,l);

OUTPUT:-

enter a string:madam

reversed string are:madam

Palindrome String

PROGRAM 19 :WRITE A PROGRAM TO COUNT THE NUMBER OF VOWELS IN A GIVEN


STRING*/

#include<stdio.h>

#include<string.h>

#define size 100

int vowel(char a[size],int l)

int i;int c=0;

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

if(a[i]=='a' || a[i]=='e' || a[i]=='i' || a[i]=='o' || a[i]=='u' || a[i]=='A' || a[i]=='E' || a[i]=='I' ||


a[i]=='O' || a[i]=='U')

c++;

return c;

void main()

{
int s,l,v;

char name[size];

printf("enter a string:");

gets(name);

l=strlen(name);

v=vowel(name,l);

printf("vowels in the string are:%d",v);

OUTPUT:-

enter a string:abhimanyu

vowels in the string are:4

PROGRAM 20 :WRITE A PROGRAM FOR ADDITION OF N X M MATRIX*/

#include <stdio.h>

#include <conio.h>

#define size 100

void input(int a[size][size], int r, int c)

int i,j;

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

printf("enter elements in row %d\n",i+1);

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

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

void display(int a[size][size], int r, int c)

int i,j;
for(i=0;i<r;i++)

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

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

printf("\n");

void sum(int a[size][size],int b[size][size],int r, int c)

int c1[size][size],i,j;

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

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

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

printf("added matrix:\n");

display(c1,r,c);

int main()

int r,c,a[size][size],b[size][size];

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

scanf("%d",&r);

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

scanf("%d",&c);

printf("enter elements in 1st matrix:\n");


input(a,r,c);

display(a,r,c);

printf("enter elements in 2nd matrix:\n");

input(b,r,c);

display(b,r,c);

sum(a,b,r,c);

OUTPUT:-

enter the number of rows:3

enter the number of rows:3

enter elements in 1st matrix:

enter elements in row 1

34

44

55

enter elements in row 2

23

44

55

enter elements in row 3

65

23

53

34 44 55

23 44 55

65 23 53

enter elements in 2nd matrix:

enter elements in row 1

65

98
99

enter elements in row 2

44

44

55

enter elements in row 3

66

22

33

65 98 99

44 44 55

66 22 33

added matrix:

99 142 154

67 88 110

131 45 86

PROGRAM 21 :WRITE A PROGRAM FOR MULTIPLICATION OF N X M MATRIX*/

#include <stdio.h>

#include <conio.h>

#define size 100

void input(int a[size][size], int r, int c)

int i,j;

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

printf("enter elements in row %d\n",i+1);

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

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

}
}

void display(int a[size][size], int r, int c)

int i,j;

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

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

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

printf("\n");

void multiply(int a[size][size],int b[size][size],int r, int c)

int c1[size][size],i,j;

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

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

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

printf("Multiplied matrix:\n");

display(c1,r,c);

int main()

int r,c,a[size][size],b[size][size];
printf("enter the number of rows:");

scanf("%d",&r);

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

scanf("%d",&c);

printf("enter elements in 1st matrix:\n");

input(a,r,c);

display(a,r,c);

printf("enter elements in 2nd matrix:\n");

input(b,r,c);

display(b,r,c);

multiply(a,b,r,c);

OUTPUT:-

enter the number of rows:2

enter the number of rows:3

enter elements in 1st matrix:

enter elements in row 1

22

33

54

enter elements in row 2

56

76

45

22 33 54

56 76 45

enter elements in 2nd matrix:

enter elements in row 1

33

44
55

enter elements in row 2

66

111

22

33 44 55

66 111 22

added matrix:

726 1452 2970

3696 8436 990

PROGRAM 22 :WRITE A PROGRAM TO COMPUTE FACTORIAL OF A GIVEN NUMBER USING


FUNCTION*/

#include <stdio.h>

#include <conio.h>

int fact(int n)

int b=1,i;

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

b=b*i;

return b;

int main()

int n;int fact1;

printf("enter a number:");

scanf("%d",&n);

fact1=fact(n);

printf("factorial=%d",fact1);

OUTPUT:-

enter a number:5
factorial=120

PROGRAM 23 :WRITE A PROGRAM FUNCTION FOR SWAPPING OF TWO NUMBERS*/

#include <stdio.h>

#include <conio.h>

#include <math.h>

void swap(int *a,int *b)

int c=*a;

*a=*b;

*b=c;

int main()

int a,b;

printf("enter two numbers:");

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

swap(&a,&b);

printf("AFTER Swapped outside function numbers are %d and %d",a,b);

OUTPUT:-

enter two numbers:67

89

AFTER Swapped outside function numbers are 89 and 67

PROGRAM 24:WRITE A PROGRAM FOR FINDING FACTORIAL OF A NUMBER USING


RECURSION*/

#include <stdio.h>

int fact(int n)

{
if(n>=1)

return n*fact(n-1);

else

return 1;

int main()

int n;int fact1;

printf("enter a number:");

scanf("%d",&n);

fact1=fact(n);

printf("factorial=%d",fact1);

OUTPUT:-

enter a number5

factorial=120

PROGRAM 25:WRITE A PROGRAM SORT AN ARRAY SUING BUBBLE SORT(USING FUNCTION)*/

#include <stdio.h>

#include <conio.h>

#define size 100

void input(int a[size], int s)

int i;

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

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

}
}

void display(int a[size], int s)

int i;

printf("Elements in the array are:\t");

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

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

void sort(int a[size],int n)

int t;int i,j;

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

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

if(a[j]>a[j+1])

t=a[j];

a[j]=a[j+1];

a[j+1]=t;

int main()

int n,a[size],b[size],c;

printf("enter the number of elements:");


scanf("%d",&n);

printf("enter elements in Array:\n");

input(a,n);

display(a,n);

sort(a,n);

printf("\nSorted array:\n");

display(a,n);

OUTPUT:-

enter the number of elements:7

enter elements in Array:

56

44

56

98

25

63

30

Elements in the array are: 56 44 56 98 25 63 30

Sorted array:

Elements in the array are: 25 30 44 56 56 63 98

PROGRAM 26 :WRITE A PROGRAM TO SEARCH A KEY NUMBER IN A ARRAY USING A


SEQUENCIAL SEARCH METHOD(USE FUNCTION)*/

#include <stdio.h>

#include <conio.h>

#define size 100

void input(int a[size], int s)

int i;

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

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

void display(int a[size], int s)

int i;

printf("Elements in the array are:\t");

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

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

void search(int a[size],int s,int c)

int i;

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

{ if(a[i]==c)

printf("the element is found at position:%d",i+1);

break;

void main()

{ int n,a[size],b[size],c;

printf("enter the number of elements:");

scanf("%d",&n);

printf("enter elements in Array:\n");

input(a,n);

display(a,n);
printf("\nEnter the element to search:-");

scanf("%d",&c);

search(a,n,c);

OUTPUT:-

enter the number of elements:5

enter elements in Array:

23

11

56

77

34

Elements in the array are: 23 11 56 77 34

Enter the element to search:-77

the element is found at position:4

PROGRAM 27:WRITE A PROGRAM USING STRUCTURE TO ACCEPT STUDENTS


DETAIL(NAME,ADMISSION NO., PHONE NO., ADDRESS, EMAIL) AND STORE THEM IN A FILE
AND PERFORM THE FOLLOWING OPERATION ON IT*/

#include<stdio.h>

#include<stdlib.h>

#define size 30

struct person

int enrollno;

char name[size];

char address[size];

int phoneno;

char email[size];

};

typedef struct person p;


void input(p *s1)

printf("enter ADMISSION NO.:");

scanf("%d",&s1->enrollno);

printf("enter name.:");

scanf("%s",&s1->name);

printf("enter address:");

scanf("%s",&s1->address);

printf("enter phone no:");

scanf("%d",&s1->phoneno);

printf("enter email:");

scanf("%s",&s1->email);

int main()

FILE *fp;

fp=fopen("f1.txt","w");

if(fp==NULL)

exit(1);

p p1;

input(&p1);

fwrite(&p2,sizeof(p),1,fp);

OUTPUT:-

enter ADMISSION NO.:1020

enter name.:ABHI

enter address:ALPHA1

enter phone no:8789523486


enter email:[email protected]

You might also like