0% found this document useful (0 votes)
2 views6 pages

Document 1

Uploaded by

bishtakhilesh79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Document 1

Uploaded by

bishtakhilesh79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q number 15

_____________________________________________________________
____

#include <stdio.h>

#include <stdlib.h>

int sumOfArray(int array[], int n) {

int sum = 0;

for (int i = 0; i < n; i++) {

sum += array[i];

return sum;

int main() {

int r, c;

printf("Enter the number of rows: ");

scanf("%d", &r);

printf("Enter the number of columns: ");

scanf("%d", &c);
int** array = (int**)malloc(r * sizeof(int*));

for (int i = 0; i < r; i++) {

array[i] = (int*)malloc(c * sizeof(int));

printf("Enter the elements of the array: \n");

for (int i = 0; i < r; i++) {

for (int j = 0; j < c; j++) {

scanf("%d", &array[i][j]);

int sum = 0;

for (int i = 0; i < r; i++) {

sum += sumOfArray(array[i], c);

printf("Sum of all the elements in the array: %d\n", sum);

for (int i = 0; i < r; i++) {

free(array[i]);
}
free(array);

return 0;

}
Q number
16___________________________________________________________
_

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void swap(char* a, char* b) {

char temp[50];

strcpy(temp, a);

strcpy(a, b);

strcpy(b, temp);

void bubbleSort(char** array, int n) {

for (int i = 0; i < n - 1; i++) {

for (int j = 0; j < n - i - 1; j++) {

if (strcmp(array[j], array[j + 1]) > 0) {

swap(array[j], array[j + 1]);

}
int main() {

int n;

printf("Enter the number of names: ");

scanf("%d", &n);

char** names = (char**)malloc(n * sizeof(char*));

for (int i = 0; i < n; i++) {

names[i] = (char*)malloc(50 * sizeof(char));

printf("Enter the names: \n");

for (int i = 0; i < n; i++) {

scanf("%s", names[i]);

bubbleSort(names, n);

printf("Names in alphabetical order: \n");

for (int i = 0; i < n; i++) {

printf("%s\n", names[i]);

}
for (int i = 0; i < n; i++) {

free(names[i]);

free(names);

return 0;

You might also like