-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.c
More file actions
173 lines (125 loc) · 3.31 KB
/
test4.c
File metadata and controls
173 lines (125 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <stdio.h>
#include <stdlib.h>
#define s 8
#define size 5
/////////////POINTER---Pass by Reference FULL EXAMPLE..........................
void findMinMax(int num1, int num2, int *pMax, int *pMin)
{
if (num1 > num2)
{
*pMin = num2;
*pMax = num1;
}
else
{
*pMin = num1;
*pMax = num2;
}
// No need for any return
}
int main ()
{
/////////////POINTER---Pass by Reference FULL EXAMPLE..........................
/*
int a = 5, b = 7;
int max, min;
findMinMax(a, b, &max, &min);
printf("max between %d and %d = %d\n", a, b, max);
printf("min between %d and %d = %d\n", a, b, min);
*/
/////////////Arrays---Arrays Copying an Array Question..........................
/*
int date [3]={1,2,2000};
int date2[3];
for (int i = 0; i < 3; i++)
{
printf ("%d ",date [i]); date2[i]=date[i];
}
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("%d ",date2 [i]);
}
*/
/////////////Arrays---Array Palindrome..........................
/*
int arr[s]={8,5,7,2,2,7,5,8};
int count=0;
for (int i = 0; i < s/2; i++)
{
if (arr[i]==arr[s-1-i]) count++;
}
if (count ==s/2) printf("Array is Palindrome");
else printf("Array is NOT Palindrome");
*/
/////////////Arrays---Arrays Largest Neighbors Sum ..........................
/*
int arr[5]={1,4,6,7,51};
int sum,maxsum=0;
for (int i = 0; i < 4; i++)
{
sum=arr[i]+arr[i+1];
if (sum>maxsum){maxsum=sum;}
}
printf("Largest Neighbors Sum=%d",maxsum);
*/
/////////////Arrays--- A Program to find if an Array is sorted ..........................
/*
int arr[size];
int Reallysorted=0,sorted=0,NOTsorted=0;
for (int i = 0; i < size; i++)
{
printf("Please enter the value of array:"); scanf("%d",&arr[i]);
}
for (int i = 0; i < size-1; i++)
{
if (arr[i]<arr[i+1]) {Reallysorted++;}
if (arr[i]==arr[i+1]) {sorted++;}
if (arr[i]>arr[i+1]) {NOTsorted++; }
}
if (sorted==0 && NOTsorted==0) printf("Reallysorted");
if (sorted!=0 && NOTsorted==0) printf("sorted");
if ( NOTsorted!=0) printf("NOTsorted");
*/
/////////////Arrays--- A Program to print and count all unique elements in an array..........................
/*
int arr[10]={5,7,3,4,5,6,8,9,10,3};
int count=0,count1=0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (arr[i]!=arr[j])
{
count++;
}
}
if (count==9){ printf("unique element=%d \n",arr[i]); count1++;}
count=0;
}
printf("number of unique element=%d ",count1);
*/
/////////////Arrays---A Program to count a total number of non unique values in an array..........................
int arr[10]={5,9,3,5,5,6,5,9,3,3},arr1[10]={0,0,0,0,0,0,0,0,0,0};
int count=0,br=0;
for (int i = 0; i < 10; i++)
{ br=0;
for (int j = 0; j < 10; j++)
{
if (arr[i]==arr[j] && i!=j )
{
for (int i1 = 0; i1 < 10; i1++)
{
if (arr1[i1]==arr[j]){br=1;}
}
if (br==0)
{
printf("NON-unique element=%d \n",arr[i]); count++;
br=0; arr1[i]=arr[i];
}
}
}
}
printf("number of NON-unique element=%d ",count);
return 0;
}