Skip to content

Commit bf57335

Browse files
committed
Tested Solutions
1 parent 51130de commit bf57335

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2476
-0
lines changed

Diff for: 2D Array - DS.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<stdio.h>
2+
#include<stdarg.h>
3+
#include<stdlib.h>
4+
int main()
5+
{
6+
int arr[6][6];
7+
char start = 1;
8+
char end = 4;
9+
int sum = 0;
10+
int sum_prev = 0;
11+
int y_index = 0;
12+
//Taking Array Input.
13+
for(int i=0; i<6; i++)
14+
{
15+
for(int j=0; j<6; j++)
16+
scanf("%d",&arr[i][j]);
17+
}
18+
for(y_index=0; y_index<4; y_index++)
19+
{
20+
for(start=0; start<3; start++)
21+
{
22+
sum = 0;
23+
for(int i=start; i<start+3; i++)
24+
{
25+
sum += arr[y_index][i];
26+
}
27+
sum += arr[y_index+1][start+1];
28+
for(int i=start; i<start+3; i++)
29+
{
30+
sum += arr[y_index+2][i];
31+
}
32+
if(sum_prev < sum)
33+
sum_prev = sum;
34+
}
35+
}
36+
printf("%d",sum_prev);
37+
}

Diff for: AccurateSorting.c

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
//Accurate Sorting.
5+
//The array elements can exchange their positions with their adjacent position elements if:
6+
// the difference between the values is 1.
7+
//If the sorted array is in the Ascending order, print YES, else No.
8+
9+
int main()
10+
{
11+
int sortArray[10];
12+
int count=0;
13+
int decider=0;
14+
printf("Enter the number of elements in the array");
15+
scanf("%d",&count);
16+
17+
for(int i=0;i<count;i++)
18+
{
19+
scanf("%d",&sortArray[i]);
20+
}
21+
for(int i=0;i<(count-1);i++)
22+
{
23+
if(sortArray[i]-sortArray[i+1]==1 || sortArray[i]-sortArray[i+1]==-1)
24+
{
25+
if(sortArray[i]-sortArray[i+1]==1)
26+
{
27+
int temp;
28+
temp=sortArray[i+1];
29+
sortArray[i+1]=sortArray[i];
30+
sortArray[i]=temp;
31+
}
32+
33+
}
34+
}
35+
for(int i=0;i<(count-1);i++)
36+
{
37+
if(sortArray[i]>sortArray[i+1])
38+
{
39+
printf("No");
40+
decider=1;
41+
}
42+
}
43+
if(decider==0)
44+
{
45+
printf("Yes");
46+
}
47+
}
48+

Diff for: AdvancedC_DivideAndConquer.c

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
5+
void mergeResults(int arr[],int start,int centre,int end)
6+
{
7+
int i,j,k;
8+
int n1 = centre-start+1; //Number of Elements from Start to Centre.
9+
int n2 = end-centre; //Number of Elements from Centre to End.
10+
11+
int L[n1]; //Create New Arrays for elements from Start to Centre.
12+
int R[n2]; //Create New Arrays for elements from Centre to End.
13+
14+
for(i=0; i<n1; i++)
15+
{
16+
L[i] = arr[start+i];
17+
}
18+
for(j=0;j<n2;j++)
19+
{
20+
R[j] = arr[centre+j+1];
21+
}
22+
23+
//Merge the Arrays back into the normal Array.
24+
i = 0;
25+
j = 0;
26+
k = start;
27+
28+
while((i<n1) && (j<n2))
29+
{
30+
if(L[i] <= R[j])
31+
{
32+
arr[k] = L[i];
33+
i++;
34+
}
35+
else
36+
{
37+
arr[k] = R[j];
38+
j++;
39+
}
40+
k++;
41+
}
42+
while(i<n1)
43+
{
44+
arr[k] = L[i];
45+
i++;
46+
k++;
47+
}
48+
while(j<n2)
49+
{
50+
arr[k] = R[j];
51+
j++;
52+
k++;
53+
}
54+
}
55+
void mergeSort(int arr[],int start,int end)
56+
{
57+
if(start < end)
58+
{
59+
int centre = ((start+end)/2);
60+
printf("Center : %d",centre);
61+
mergeSort(arr,start,centre);
62+
mergeSort(arr,centre+1,end);
63+
mergeResults(arr,start,centre,end);
64+
}
65+
}
66+
int main()
67+
{
68+
//Divide and Conquer Algorithm.
69+
printf("Start Learning Advanced C ! \n");
70+
71+
int arr[] = {1,5,8,7,9};
72+
int arr_size = sizeof(arr)/sizeof(arr[0]);
73+
printf("Size of Array is : %d",arr_size);
74+
75+
mergeSort(arr,0,(arr_size-1));
76+
77+
while(arr_size)
78+
{
79+
printf("\n %d",arr[5-arr_size]);
80+
arr_size--;
81+
}
82+
83+
return 0;
84+
85+
86+
}

Diff for: AdvancedC_DivideAndConquer_BinarySearch.c

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
5+
//Incomplete.
6+
7+
int search(int arr[], int start, int centre ,int end,int search_element)
8+
{
9+
int n1 = centre - start + 1;
10+
int n2 = end - centre;
11+
int i,j;
12+
while((i<n1) && (j<n2))
13+
{
14+
15+
}
16+
17+
}
18+
void divide(int arr[], int start, int end,int search_element)
19+
{
20+
if(start < end)
21+
{
22+
int centre = ((start+end)/2);
23+
divide(arr,start,centre);
24+
divide(arr,centre+1,end);
25+
int status = search(arr,start,centre,end,search_element);
26+
}
27+
}
28+
29+
int main()
30+
{
31+
int arr[] = {2,5,8,9,3,5};
32+
int size_arr = (sizeof(arr)/sizeof(arr[0]));
33+
34+
35+
divide(arr,0,(size_arr-1));
36+
37+
//Printing the Array.
38+
while(size_arr)
39+
{
40+
printf("%d \n",arr[6-size_arr]);
41+
size_arr--;
42+
}
43+
44+
return 0;
45+
}

Diff for: Apples&Oranges.c

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
//Apple and Orange
4+
//Given the position of the Start and end points of the House and the positions of Apple and Orange Tree.
5+
//Also given the Number of apples and Oranges and their position of Fall on the ground.
6+
// Determine how many Apple and Oranges will fall into the House.
7+
8+
9+
void main()
10+
{
11+
int start=0;
12+
int end=0;
13+
int posAppleTree=0;
14+
int posOrangeTree=0;
15+
int countApple=0;
16+
int countOrange=0;
17+
int distanceAppleTree=0;
18+
int distanceOrangetree=0;
19+
int AppleHome=0;
20+
int OrangeHome=0;
21+
22+
printf("Enter the Start point of the house :");
23+
scanf("%d",&start);
24+
printf("Enter the End point of the House :");
25+
scanf("%d",&end);
26+
printf("Position of the Apple Tree :");
27+
scanf("%d",&posAppleTree);
28+
printf("Position of the Orange Tree :");
29+
scanf("%d",&posOrangeTree);
30+
printf("Number of Apples on the tree :");
31+
scanf("%d",&countApple);
32+
printf("Number of Oranges on the Tree :");
33+
scanf("%d",&countOrange);
34+
35+
int positionApple[countApple];
36+
int positionOrange[countOrange];
37+
38+
distanceAppleTree=posAppleTree-start;
39+
distanceOrangetree=posOrangeTree-end;
40+
41+
for(int i=0;i<countApple;i++)
42+
{
43+
printf("Enter the Position of fall of Apple %d :",(i+1));
44+
scanf("%d",&positionApple[i]);
45+
if(positionApple[i]<=(distanceAppleTree))
46+
AppleHome++;
47+
}
48+
printf("The apples which falls into the House are : %d \n",AppleHome);
49+
for (int i=0;i<countOrange;i++)
50+
{
51+
printf("Enter the position of fall of Orange %d :",(i+1));
52+
scanf("%d",&positionOrange[i]);
53+
if(positionOrange[i]>=distanceOrangetree)
54+
OrangeHome++;
55+
}
56+
printf("The Oranges which fall into the House are : %d",OrangeHome);
57+
}

Diff for: BeautifulWord.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
//Beautiful Word.
5+
//To check if :
6+
// 1- two consecutive characters of the string are same.
7+
// 2- two consecutive characters of the string are vowels.
8+
// if yes: the word is not beautiful, else it is beautiful.
9+
10+
int main()
11+
{
12+
char word[50];
13+
printf("Enter the word:");
14+
int decider=0;
15+
scanf("%s",&word);
16+
int i=0;
17+
while(word[i]!='\0')
18+
{
19+
if(word[i]==word[i+1])
20+
{
21+
decider=1;
22+
break;
23+
}
24+
else if(word[i]=='a' || word[i]=='e' || word[i]=='i' || word[i]=='u' || word[i]=='o' || word[i]=='y' )
25+
{
26+
if(word[i+1]=='a' || word[i+1]=='e' || word[i+1]=='i' || word[i+1]=='u' || word[i+1]=='o' || word[i+1]=='y')
27+
{
28+
decider=1;
29+
break;
30+
}
31+
}
32+
i++;
33+
}
34+
if(decider==1)
35+
{
36+
printf("The word is not beautiful");
37+
}
38+
else
39+
printf("The word is beautiful");
40+
41+
}
42+

0 commit comments

Comments
 (0)