You are on page 1of 6

NAME : S.

SANTHOSH REDDY

ROLL NO : 21S116205

SECTION:H1

SUBJECT:PROBLEM SOLVING TECHNIQUES WITH C AND C++

1.Reverse of an array

#include <stdio.h>

int main()

//Initialize array

int arr[] = {1, 2, 3, 4, 5};

//Calculate length of array arr

int length = sizeof(arr)/sizeof(arr[0]);

printf("Original array: \n");

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

printf("%d ", arr[i]);

printf("\n");

printf("Array in reverse order: \n");

//Loop through the array in reverse order

for (int i = length-1; i >= 0; i--) {

printf("%d ", arr[i]);

return 0;

}
2. C program to. Find smallest elements of an array

//Initialize array

int arr[] = {25, 11, 7, 75, 56};

//Calculate length of array arr

int length = sizeof(arr)/sizeof(arr[0]);

//Initialize min with first element of array.

int min = arr[0];

//Loop through the array

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

//Compare elements of array with min

if(arr[i] < min)

min = arr[i];

printf("Smallest element present in given array: %d\n", min);

return 0;

3.To find largest element of an array program

#include <stdio.h>

int main()

//Initialize array

int arr[] = {25, 11, 7, 75, 56};


//Calculate length of array arr

int length = sizeof(arr)/sizeof(arr[0]);

//Initialize min with first element of array.

int min = arr[0];

//Loop through the array

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

//Compare elements of array with min

if(arr[i] < min)

min = arr[i];

printf("Smallest element present in given array: %d\n", min);

return 0;

4.Write a c program to remove duplicate elements

#include <stdio.h>

int main()

int a[50],i,j,k, count = 0, dup[50], number;

printf("Enter size of the array\n");

scanf("%d",&number);

printf("Enter Elements of the array:\n");

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

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

dup[i] = -1;

printf("Entered element are: \n");

for(i=0;i<number;i++){
printf("%d ",a[i]);

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

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

if(a[i] == a[j]){

for(k = j; k <number; k++){

a[k] = a[k+1];

j--;

number--;

printf("\nAfter deleting the duplicate element the Array is:\n");

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

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

5.write a C program to reverse any number

#include <stdio.h>

int main()

int n, rev = 0, remainder;

printf("Enter an integer: ");

scanf("%d", &n);

while (n != 0) {

remainder = n % 10;

rev = rev * 10 + remainder;

n /= 10;
}

printf("Reversed number = %d", rev);

return 0;

6.write a C program to subtraction two matrices.

#include <stdio.h>

int main()

int i, j, rows, columns, a[10][10], b[10][10];

int Subtraction[10][10];

printf("\n Please Enter Number of rows and columns : ");

scanf("%d %d", &i, &j);

printf("\n Please Enter the First Matrix Elements\n");

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

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

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

printf("\n Please Enter the Second Matrix Elements\n");

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

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

scanf("%d", &b[rows][columns]);
}

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

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

Subtraction[rows][columns] = a[rows][columns] - b[rows][columns];

printf("\n After Subtracting Matrix a from Matrix b = a - b \n");

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

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

printf("%d \t ", Subtraction[rows][columns]);

printf("\n");

return 0;

You might also like