-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00e5d46
commit e4506c8
Showing
9 changed files
with
215 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
// int arr1[]={2,3,5,4,4,7,1,6}; | ||
// int arr2[]={7,8,9,3,3,3,9,5}; | ||
int arr1[8],arr2[10]; | ||
printf("enter 1st array \n"); | ||
for (int i = 0; i < 8; i++) | ||
{ | ||
scanf("%d",&arr1[i]); | ||
} | ||
printf("enter 2nd array \n"); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
scanf("%d",&arr2[i]); | ||
} | ||
int min=8<10?8:10; | ||
int commonElement[min],countCommon=0; | ||
|
||
for (int i = 0; i < 8; i++) | ||
{ | ||
for (int j = 0; j < 10; j++) | ||
{ | ||
if (arr1[i]==arr2[j]) | ||
{ | ||
commonElement[countCommon++]=arr1[i]; | ||
break; | ||
} | ||
} | ||
} | ||
printf("common elements are :"); | ||
for (int i = 0; i < countCommon; i++) | ||
{ | ||
printf("%d ",commonElement[i]); | ||
} | ||
|
||
|
||
return 0; | ||
} |
34 changes: 34 additions & 0 deletions
34
06-Arrays_&_multidimension_Arrays/ExercSoln/secondLargest.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
int n; | ||
printf("enter no. of elements:"); | ||
scanf("%d",&n);//7 | ||
int arr[n]; | ||
printf("enter %d elements \n",n); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
scanf("%d",&arr[i]); | ||
} | ||
//bubble sort | ||
for (int pass = 0; pass < n-1; pass++) | ||
{ | ||
for (int j = 0; j < n-pass-1; j++) | ||
{ | ||
if (arr[j]>arr[j+1]) | ||
{ | ||
int c=arr[j]; | ||
arr[j]=arr[j+1]; | ||
arr[j+1]=c; | ||
} | ||
} | ||
} | ||
printf("the sorted array is \n"); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
printf(" %d ",arr[i]); | ||
} | ||
printf("\nthe second largest element is %d \n",arr[n-2]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
int arr[10],times,unique[10],uniqueCount=0; | ||
printf("enter the elements in array:\n"); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
scanf("%d",&arr[i]); | ||
} | ||
|
||
//find unique elements | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
times=0; | ||
for (int j = 0; j < 10; j++) | ||
{ | ||
if (arr[i]==arr[j]) | ||
times++; | ||
} | ||
if(times==1) | ||
{ | ||
unique[uniqueCount++]=arr[i]; | ||
// printf("%d is unique\n",arr[i]); | ||
} | ||
} | ||
|
||
printf("the unique elements are :"); | ||
for (int i = 0; i < uniqueCount; i++) | ||
printf("%d ",unique[i]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
int n; | ||
printf("enter the size of array:"); | ||
scanf("%d",&n); | ||
|
||
int boxes[n];// 10,45,67 | ||
printf("enter the no. of books\n"); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
scanf("%d",&boxes[i]); | ||
} | ||
int box2[n]; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
// box2[i]=boxes[i]; | ||
box2[n-i-1]=boxes[i]; | ||
} | ||
printf("the content of box2 is \n"); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
printf(" %d ",box2[i]); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
// int arr[]={23,775,960,144,155,844,783,989,492,829,861,735,574,18,491,900,37,326,77,192,171,550,846,459,877,915,658,601,132,174,429,440,629,253,880,783,48,29,885,941,614,140,429,576,325,175,988,522,51}; | ||
// int len=sizeof(arr)/sizeof(4); | ||
// printf("the length of array is %d \n",len); | ||
|
||
int arr[10]; | ||
printf("enter 10 values\n"); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
scanf("%d",&arr[i]); | ||
} | ||
|
||
int key,isfound=0; | ||
printf("enter value to be searched:"); | ||
scanf("%d",&key); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
if (arr[i]==key) | ||
{ | ||
printf("found at position %d \n",i); | ||
isfound=1; | ||
break; | ||
} | ||
} | ||
if (isfound!=1) | ||
{ | ||
printf("not found in array \n"); | ||
} | ||
return 0; | ||
} |