Report4 Array
Report4 Array
Sample Input :
Print all unique elements of an array:
------------------------------------------
Input the number of elements to be stored in the array: 4
Input 4 elements in the array :
element - 0 : 3
element - 1 : 2
element - 2 : 2
element - 3 : 5
Sample Output :
The unique elements found in the array are:
3 5
#include <stdio.h>
int main() {
int n, x, y;
printf("Input the number of elements to be stored in the array: ");
scanf("%d", &n);
int a[n];
printf("Input %d elements in the array:\n", n);
for (x = 0; x < n; x++) {
printf("element -%d : ",x);
scanf("%d", &a[x]);
}
return 0;
}
Sample Output:
The merged array in decending order is :
332211
#include <stdio.h>
int main() {
int n;
printf("Input the number of elements to be stored in the first array: ");
scanf("%d", &n);
while (x >= 0) {
merged[z++] = a1[x--];
}
while (y >= 0) {
merged[z++] = a2[y--];
}
printf("The merged array in descending order is:\n");
for (int x = 0; x < 2 * n; x++) {
printf("%d ", merged[x]);
}
return 0;
}
Sample Output:
Elements of array in sorted descending order:
97542
#include <stdio.h>
int main() {
int n, x, y, de;
printf("Input the size of array:");
scanf("%d", &n);
int a[n];
printf("Input %d elements in the array:\n", n);
for (x = 0; x < n; x++) {
printf("element -%d : ",x);
scanf("%d", &a[x]);
}
for(x = 0; x < n-1; x++){
for (y = x+1; y < n; y++){
if (a[x] < a[y]){
de = a[x];
a[x] = a[y];
a[y] = de;
}
}
}
printf(" Elements of array in shorted descending order:\n");
for ( x = 0; x < n; x++){
printf("%d ", a[x]);
}
printf("\n");
return 0;
}
#include <stdio.h>
int main() {
int n, x, y, large, sec_large;
printf("Input the size of array: ");
scanf("%d", &n);
int a[n];
printf("Input %d elements in the array:\n", n);
for (x = 0; x < n; x++) {
printf("element -%d : ",x);
scanf("%d", &a[x]);
}
large = a[0];
for (x =1; x < n; x++){
if (a[x]> large){
large=a[x];
}
}
sec_large = a[0];
for (x = 1; x < n; x++){
if(a[x] > sec_large && a[x] != large){
sec_large = a[x];
}
}
return 0;}
INPUT & OUTPUT
5.Write a program in C to replace the spaces in a string with a specific character.
Sample Input:
Input a string : Be glad to see the back of
Input replace character : *
Sample Output:
Source Code
#include <stdio.h>
int main()
{
return 0;
}
Sample Input:
Input a character : w
Sample Output:
#include <stdio.h>
int main() {
char ch;
} else {
return 0;
Sample Input:
Input a character : 8
Sample Output:
int main() {
char x;
printf("Input a character: ");
scanf(" %c", &x);
return 0;
}
Sample Input:
Sample Output:
bIOmEdIcAl EngInEErIng
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
printf("Input a string: ");
gets(str);
return 0;
}