Smallest and Largest Number

20
SHAKTHIDHAR/ CP LAB/ CSE I PROGRAM /*program to find smallest and largest of n numbers*/ #include<stdio.h> #include<conio.h> void main() { int i, sm, a[50], la, l; clrscr(); printf("\n SMALLEST AND LARGEST NUMBER \n\n"); printf("Enter the limit : "); scanf("%d", &l); printf("Enter the numbers \n"); for(i=0;i<l;i++) { scanf("%d", &a[i]); } sm = a[0]; la = a[0]; for(i=1;i<l;i++) { if(a[i]>la) { la = a[i]; } if(a[i]<sm) { sm = a[i]; } } printf("\n Largest number : "); printf("%d",la); printf("\n Smallest number : "); printf("%d", sm); getch(); }

description

a

Transcript of Smallest and Largest Number

Page 1: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

PROGRAM

/*program to find smallest and largest of n numbers*/ #include<stdio.h> #include<conio.h> void main() { int i, sm, a[50], la, l; clrscr(); printf("\n SMALLEST AND LARGEST NUMBER \n\n"); printf("Enter the limit : "); scanf("%d", &l); printf("Enter the numbers \n"); for(i=0;i<l;i++) { scanf("%d", &a[i]); } sm = a[0]; la = a[0]; for(i=1;i<l;i++) { if(a[i]>la) { la = a[i]; } if(a[i]<sm) { sm = a[i]; } } printf("\n Largest number : "); printf("%d",la); printf("\n Smallest number : "); printf("%d", sm); getch(); }

Page 2: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

OUTPUT

SMALLEST AND LARGEST NUMBER

Enter the limit : 5

Enter the numbers

4 6 9 3 34

Largest number : 34

Smallest number : 3

Page 3: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

PROGRAM

/*implementation of addition and subrataction of matrices*/ #include<stdio.h> #include<conio.h> void main() { int a[10][10], b[10][10], c[10][10], i, j, n, m; clrscr(); printf("ADDITION AND SUBTRACTION OF MATRICES\n\n"); printf("Enter the rows and columns of the matrix : "); scanf("%d %d", &m, &n); printf("\n Enter the elements of matrix A\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&a[i][j]); } } printf("\nEnter the elements of matrix B\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&b[i][j]); } } printf("\n The elements of the matrix A are \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { printf("\t%d",a[i][j]); } } printf("\n The elements of the matrix B are \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) {

Page 4: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

printf("\t%d",b[i][j]); } } printf("\n Addition of two matrices is \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { c[i][j] = a[i][j] + b[i][j]; printf("\t%d",c[i][j]); } } printf("\n Subtraction of two matrices is \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { c[i][j] = a[i][j] - b[i][j]; printf("\t%d",c[i][j]); } } getch(); }

Page 5: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

OUTPUT ADDITION AND SUBTRACTION OF MATRICES

Enter the rows and columns of the matrix : 3 3

Enter the elements of matrix A

1 2 3 4 5 6 7 8 89

Enter the elements of matrix B

9 8 7 6 5 4 3 2 1

The elements of the matrix A are

1 2 3

4 5 6

7 8 89

The elements of the matrix B are

9 8 7

6 5 4

3 2 1

Addition of two matrices is

10 10 10

10 10 10

10 10 90

Subtraction of two matrices is

-8 -6 -4

-2 0 2

4 6 88

Page 6: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

PROGRAM /*implementation of multiplication of matrices */ #include<stdio.h> #include<conio.h> void main() { int a[10][10], b[10][10], c[10][10], i, j, n, m, k; clrscr(); printf("MATRIX MULTIPLICATION\n\n"); printf("Enter the rows and columns of the matrix : "); scanf("%d %d", &m, &n); printf("\n Enter the elements of matrix A\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&a[i][j]); } } printf("\nEnter the elements of matrix B\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&b[i][j]); } } printf("\n The elements of the matrix A are \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { printf("\t%d",a[i][j]); } } printf("\n The elements of the matrix B are \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++)

Page 7: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

{ printf("\t%d",b[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { c[i][j] = 0; for(k=0;k<m;k++) { c[i][j] = c[i][j] + (a[i][k] * b[k][j]); } } } printf("\n Resultant matrix is \n"); for(i=0;i<n;i++) { printf("\n"); for(j=0;j<m;j++) { printf("\t%d",c[i][j]); } } getch(); }

Page 8: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

OUTPUT

MATRIX MULTIPLICATION

Enter the rows and columns of the matrix : 3 3

Enter the elements of matrix A

1 2 3 4 5 6 7 8 9

Enter the elements of matrix B 1 2 9 8 7 6 5 4 6

The elements of the matrix A are

1 2 3

4 5 6

7 8 9

The elements of the matrix B are

1 2 9

8 7 6

5 4 6

Resultant matrix is

32 28 39

74 67 102

116 106 165

Page 9: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

PROGRAM

//number of occurences in an array #include<stdio.h> #include<conio.h> void main() { int i, n, a[50], l, c = 0; clrscr(); printf("\n NUMBER OF OCCURENCES \n\n"); printf("Enter the limit : "); scanf("%d", &l); printf("Enter the numbers \n"); for(i=0;i<l;i++) { scanf("%d", &a[i]); } printf("\n Enter the element to be found : "); scanf("%d",&n); for(i=0;i<l;i++) { if(a[i]==n) { c = c + 1; } } if(c>0) { printf("\n The number is found in %d times",c); } else { printf("\n The number is not present in this array\n "); } getch(); }

Page 10: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

OUTPUT

NUMBER OF OCCURENCES

Enter the limit : 5

Enter the numbers

3 4 4 5 3

Enter the element to be found : 4

The number is found in 2 times

Page 11: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

PROGRAM

//finding the element and sorting an array #include<stdio.h> #include<conio.h> void main() { int i, n, a[50], l, c; clrscr(); printf("\n FIND THE ELEMENT IN AN ARRAY \n\n"); printf("Enter the limit : "); scanf("%d", &l); printf("Enter the numbers \n"); for(i=0;i<l;i++) { scanf("%d", &a[i]); } printf("\n Enter the element to be found : "); scanf("%d",&n); for(i=0;i<l;i++) { if(a[i]==n) { c=1; printf("The number is found in %d position\n",i+1); } } if(c!=1) printf("\n The number is not present in this array\n "); getch(); }

Page 12: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

OUTPUT

FIND THE ELEMENT IN AN ARRAY

Enter the limit : 5

Enter the numbers

1 2 3 4 5

Enter the element to be found : 2

The number is found in 2 position

Page 13: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

PROGRAM

//sorting an array in ascending and descending order #include<stdio.h> #include<conio.h> void main() { int i, j, a[50], temp, l; clrscr(); printf("\n ASCENDING AND DESCENDING ORDER \n\n"); printf("Enter the limit : "); scanf("%d", &l); printf("Enter the numbers \n"); for(i=0;i<l;i++) { scanf("%d", &a[i]); } for(i=0;i<l;i++) { for(j=i+1;j<l;j++) { if(a[i]>a[j]) { temp = a[j]; a[j] = a[i]; a[i] = temp; } } } printf("\n Ascending Order \n"); for(i=0;i<l;i++) { printf("%d\t",a[i]); } printf("\n Descending Order \n"); for(i=l-1;i>=0;i--) { printf("%d\t", a[i]); } getch(); }

Page 14: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

OUTPUT ASCENDING AND DESCENDING ORDER

Enter the limit : 5

Enter the numbers

7 5 6 2 1

Ascending Order

1 2 5 6 7

Descending Order

7 6 5 2 1

Page 15: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

Page 16: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

Page 17: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

Page 18: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

Page 19: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I

Page 20: Smallest and Largest Number

SHAKTHIDHAR/ CP LAB/ CSE I