-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.c
More file actions
146 lines (130 loc) · 3.67 KB
/
Array.c
File metadata and controls
146 lines (130 loc) · 3.67 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
// Write a program to sort given 10 numbers in ascending order.
#include <stdio.h>
int main() {
int numbers[10], i, j, temp;
printf("Enter 10 numbers:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &numbers[i]);
}
for (i = 0; i < 10 - 1; i++) {
for (j = 0; j < 10 - i - 1; j++) {
if (numbers[j] > numbers[j + 1]) {
temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
printf("Numbers in ascending order:\n");
for (i = 0; i < 10; i++) {
printf("%d ", numbers[i]);
}
printf("\n");
return 0;
}
// Write a program to find the transpose of the 3x3 matrixes
#include <stdio.h>
int main() {
int matrix[3][3], transpose[3][3], multiplication[3][3];
int i, j, k;
printf("Enter elements of 3x3 matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &matrix[i][j]);
}
}
// Compute transpose of the matrix
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
transpose[j][i] = matrix[i][j];
}
}
// Print the transpose
printf("Transpose of the matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
// Compute multiplication of matrix with itself
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
multiplication[i][j] = 0;
for (k = 0; k < 3; k++) {
multiplication[i][j] += matrix[i][k] * matrix[k][j];
}
}
}
// Print the multiplication result
printf("Multiplication of the matrix with itself:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", multiplication[i][j]);
}
printf("\n");
}
return 0;
}
// Write a program, which reads a string from the keyboard and generates the alphabetical order of characters that represents the string. Eg. PROGRAM should be written as AGMOPRR.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 100
int main() {
char str[MAX], temp;
int i, j;
printf("Enter a string: ");
fgets(str, MAX, stdin);
// Remove newline character if present
str[strcspn(str, "\n")] = '\0';
// Convert string to uppercase
for (i = 0; str[i]; i++) {
str[i] = toupper(str[i]);
}
// Sort the string
for (i = 0; str[i]; i++) {
for (j = i + 1; str[j]; j++) {
if (str[i] > str[j]) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
printf("Alphabetical order: %s\n", str);
return 0;
}
// Write a program to check whether the string is a palindrome or not.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 100
int main() {
char str[MAX], reversed[MAX];
int i, length, isPalindrome = 1;
printf("Enter a string: ");
fgets(str, MAX, stdin);
// Remove newline character if present
str[strcspn(str, "\n")] = '\0';
// Convert string to lowercase
for (i = 0; str[i]; i++) {
str[i] = tolower(str[i]);
}
length = strlen(str);
// Reverse the string
for (i = 0; i < length; i++) {
reversed[i] = str[length - i - 1];
}
reversed[length] = '\0';
// Check if the original string is the same as the reversed string
if (strcmp(str, reversed) != 0) {
isPalindrome = 0;
}
if (isPalindrome) {
printf("The string is a palindrome.\n");
} else {
printf("The string is not a palindrome.\n");
}
return 0;
}