0% found this document useful (0 votes)
20 views3 pages

Bubble Sort Count Vowels, Constant, Space Matrix Multiplication Matrixs Addition

The document contains multiple C programming code snippets for various algorithms and operations including bubble sort, matrix operations (addition, multiplication, subtraction, transposition), factorial calculation, and linear search. Each section provides a brief overview of the functionality, input requirements, and output results. Overall, it serves as a collection of fundamental programming exercises and examples in C.

Uploaded by

matrix29v
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)
20 views3 pages

Bubble Sort Count Vowels, Constant, Space Matrix Multiplication Matrixs Addition

The document contains multiple C programming code snippets for various algorithms and operations including bubble sort, matrix operations (addition, multiplication, subtraction, transposition), factorial calculation, and linear search. Each section provides a brief overview of the functionality, input requirements, and output results. Overall, it serves as a collection of fundamental programming exercises and examples in C.

Uploaded by

matrix29v
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/ 3

Bubble sort Count vowels, constant, space Matrix Multiplication Matrixs addition

#include <stdio.h> #include <stdio.h> #include <stdio.h> #include <stdio.h>


void bubbleSort(int array[], int size) { #include <ctype.h> int main() { int main() {
for (int step = 0; step < size - 1; ++step) { int main() { int m, n, p, q, c, d, k, sum = 0; int r, c, a[100][100], b[100][100], sum[100][100], i,
for (int i = 0; i < size - step - 1; ++i) { char line[150]; int rst[10][10], second[10][10], multiply[10][10]; j;
if (array[i] > array[i + 1]) { int vowels, consonant, digit, space; printf("Enter number of rows and columns of rst printf("Enter the number of rows (between 1 and
int temp = array[i]; vowels = consonant = digit = space = 0; matrix\n"); 100): ");
array[i] = array[i + 1]; printf("Enter a line of string: "); scanf("%d%d", &m, &n); scanf("%d", &r);
array[i + 1] = temp; fgets(line, sizeof(line), stdin); printf("Enter elements of rst matrix\n"); printf("Enter the number of columns (between 1
} for (int i = 0; line[i] != '\0'; ++i) { for (c = 0; c < m; c++) and 100): ");
} line[i] = tolower(line[i]); for (d = 0; d < n; d++) scanf("%d", &c);
} if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || scanf("%d", & rst[c][d]); printf("\nEnter elements of 1st matrix:\n");
} line[i] == 'o' || line[i] == 'u') { printf("Enter number of rows and columns of for (i = 0; i < r; ++i)
void printArray(int array[], int size) { ++vowels; second matrix\n"); for (j = 0; j < c; ++j) {
for (int i = 0; i < size; ++i) { } scanf("%d%d", &p, &q); printf("Enter element a%d%d: ", i + 1, j + 1);
printf("%d ", array[i]); else if ((line[i] >= 'a' && line[i] <= 'z')) { if (n != p) scanf("%d", &a[i][j]);
} ++consonant; printf("The multiplication isn't possible.\n"); }
printf("\n"); } else { printf("Enter elements of 2nd matrix:\n");
} else if (line[i] >= '0' && line[i] <= '9') { printf("Enter elements of second matrix\n"); for (i = 0; i < r; ++i)
int main() { ++digit; for (c = 0; c < p; c++) for (j = 0; j < c; ++j) {
int data[] = {-2, 45, 0, 11, -9}; } for (d = 0; d < q; d++) printf("Enter element b%d%d: ", i + 1, j + 1);
int size = sizeof(data) / sizeof(data[0]); else if (line[i] == ' ') { scanf("%d", &second[c][d]); scanf("%d", &b[i][j]);
bubbleSort(data, size); ++space; for (c = 0; c < m; c++) { }
printf("Sorted Array in Ascending Order:\n"); } for (d = 0; d < q; d++) { for (i = 0; i < r; ++i)
printArray(data, size); } for (k = 0; k < p; k++) { for (j = 0; j < c; ++j) {
} printf("Vowels: %d", vowels); sum = sum + rst[c][k]*second[k][d]; sum[i][j] = a[i][j] + b[i][j];
printf("\nConsonants: %d", consonant); } }
printf("\nDigits: %d", digit); multiply[c][d] = sum; printf("\nSum of two matrices: \n");
printf("\nWhite spaces: %d", space); sum = 0; for (i = 0; i < r; ++i)
return 0; } for (j = 0; j < c; ++j) {
} } printf("%d ", sum[i][j]);
printf("Product of the matrices:\n"); if (j == c - 1) {
for (c = 0; c < m; c++) { printf("\n\n");
for (d = 0; d < q; d++) }
printf("%d\t", multiply[c][d]); }
printf("\n"); return 0;
} }
}
return 0;
}

Quadratic Equation Factorial of a Number Sort n Numbers Sum and average of array
#include <math.h> #include<stdio.h> #include <stdio.h> #include <stdio.h>
#include <stdio.h> long int multiplyNumbers(int n); void sorting(int numbers[],int num) { int main()
int main() int main() { int temp; {
{ int n; for (int i = 0; i < num; i++) { int i=0, sum=0, avg, in, size, num;
double a, b, c, discriminant, root1, root2, printf("Enter a positive integer: "); for (int j = i+1; j < num; j++) { int array[size];
realPart, imagPart; scanf("%d",&n); if (numbers[i]>numbers[j]) { printf("Enter the number elements in the
printf("Enter coe cients a, b and c: "); printf("Factorial of %d = %ld", n, temp=numbers[i]; array :");
scanf("%lf %lf %lf", &a, &b, &c); multiplyNumbers(n)); numbers[i]=numbers[j]; scanf("%d",&size);
discriminant = b * b - 4 * a * c; return 0; numbers[j]=temp; for (int i = 0; i < size; i++)
if (discriminant > 0) { } } {
root1 = (-b + sqrt(discriminant)) / (2 * a); long int multiplyNumbers(int n) { } printf("Enter the %d value :",i+1);
root2 = (-b - sqrt(discriminant)) / (2 * a); if (n>=1) } scanf("%d",&array[i]);
printf("root1 = %.2lf and root2 = %.2lf", return n*multiplyNumbers(n-1); printf("\nAll number sorted in assending order.\n"); }
root1, root2); else for (int k = 0; k < num; k++) { for(i=0;i<size;i++)
} return 1; printf("%d\n",numbers[k]); {
else if (discriminant == 0) { } } in = array[i];
root1 = root2 = -b / (2 * a); Palindrome or not printf("Assending order sorting is completed. sum = sum + in;
printf("root1 = root2 = %.2lf;", root1); #include <stdio.h> \n\n"); }
} int main() { } avg = sum/size;
else { int n, reversed = 0, remainder, original; int main() { printf("The sum of the elements in array is
realPart = -b / (2 * a); printf("Enter an integer: "); int numbers[100],num; %d\n",sum);
imagPart = sqrt(-discriminant) / (2 * a); scanf("%d", &n); char check; printf("The average of the elements in array is
printf("root1 = %.2lf+%.2l and root2 = original = n; printf("Enter how many numbers you want to %d\n",avg);
%.2f-%.2 ", realPart, imagPart, realPart, while (n != 0) { sort:"); }
imagPart); remainder = n % 10; scanf("%d",&num);
} reversed = reversed * 10 + remainder; printf("Enter the numbers for sorting.\n");
return 0; n /= 10; for (int i = 0; i < num; i++) {
} } printf("Enter the %d value :",i);
if (original == reversed) scanf("%d",&numbers[i]);
printf("%d is a palindrome.", original); }
else sorting(numbers,num);
printf("%d is not a palindrome.", original); }
return 0;
}
fi
fi
fi
ffi
fi
fi
fi
fi
Matrixs Subtraction Matrix Transposal TRACE OF MATRIX Factorial of a Number Using Recursion
#include <stdio.h> #include <stdio.h> #include <stdio.h> #include<stdio.h>
int main() int main() { #include <math.h> long int multiplyNumbers(int n);
{ int a[10][10], transpose[10][10], r, c; int main() {
int m, n, c, d, rst[10][10], second[10][10], printf("Enter rows and columns: "); int main () int n;
di erence[10][10]; scanf("%d %d", &r, &c); { printf("Enter a positive integer: ");
printf("Enter the number of rows and columns of printf("\nEnter matrix elements:\n"); static int array[10][10]; scanf("%d",&n);
matrix\n"); for (int i = 0; i < r; ++i) int i, j, m, n, sum = 0, sum1 = 0, a = 0, normal; printf("Factorial of %d = %ld", n,
scanf("%d%d", &m, &n); for (int j = 0; j < c; ++j) { printf("Enter the order of the matrix\n"); multiplyNumbers(n));
printf("Enter the elements of rst matrix\n"); printf("Enter element a%d%d: ", i + 1, j + 1); scanf("%d %d", &m, &n); return 0;
for (c = 0; c < m; c++) scanf("%d", &a[i][j]); printf("Enter the n coe cients of the matrix \n"); }
for (d = 0 ; d < n; d++) } for (i = 0; i < m; ++i) long int multiplyNumbers(int n) {
scanf("%d", & rst[c][d]); printf("\nEntered matrix: \n"); { if (n>=1)
printf("Enter the elements of second matrix\n"); for (int i = 0; i < r; ++i) for (j = 0; j < n; ++j) return n*multiplyNumbers(n-1);
for (c = 0; c < m; c++) for (int j = 0; j < c; ++j) { { else
for (d = 0; d < n; d++) printf("%d ", a[i][j]); scanf("%d", &array[i][j]); return 1;
scanf("%d", &second[c][d]); if (j == c - 1) a = array[i][j] * array[i][j]; }
printf("Di erence of entered matrices:-\n"); printf("\n"); sum1 = sum1 + a; Decimal to binary
for (c = 0; c < m; c++) { } } #include <stdio.h>
for (d = 0; d < n; d++) { for (int i = 0; i < r; ++i) } void decToBinary(int n) {
di erence[c][d] = rst[c][d] - second[c][d]; for (int j = 0; j < c; ++j) { normal = sqrt(sum1); int binaryNum[56];
printf("%d\t",di erence[c][d]); transpose[j][i] = a[i][j]; printf("The normal of the given matrix is = int i = 0;
} } %d\n", normal); while (n > 0) {
printf("\n"); printf("\nTranspose of the matrix:\n"); for (i = 0; i < m; ++i) binaryNum[i] = n % 2;
} for (int i = 0; i < c; ++i) { n = n / 2;
return 0; for (int j = 0; j < r; ++j) { sum = sum + array[i][i]; i++;
} printf("%d ", transpose[i][j]); } }
if (j == r - 1) printf("Trace of the matrix is = %d\n", sum); for (int j = i - 1; j >= 0; j--)
printf("\n"); } printf("%d", binaryNum[j]);
} }
return 0; int main() {
} int n;
printf("Enter an integer: ");
scanf("%d", &n);
decToBinary(n);
return 0;
}

Students Details Structure Fibinocii Series Product details structure Linear search
#include <stdio.h> #include<stdio.h> #include <stdio.h> #include<stdio.h>
struct student { void bonacciSeries(int range){ struct student { int main() {
char name[50]; int a=0, b=1, c; int index; int a[]={4,5,6,7,8,9};
char address[50]; while (a<=range) { char name[50]; int i=0;
char dob[50]; printf("%d\t", a); int price; int decision=0;
}; c = a+b; int quantity; int n;
int main() { a = b; } s[2]; printf("Enter the search element :");
struct student s; b = c; int main() { scanf("%d",&n);
printf("Enter The Information of Students :\n"); } int i, pp=0,tp=0; while(I<=5) {
printf("Enter Name : "); } printf("Enter information of products:\n"); if(n==a[I]) {
scanf("%s",s.name); int main() { for (i = 0; i < 2; ++i) { decision++;
printf("Enter the address of the student : "); int range; s[i].index = i + 1; }
scanf("%s",s.address); printf("Enter range: "); printf("\nFor product number%d,\n", i++;
printf("Enter the date of birth of the student : "); scanf("%d", &range); s[i].index); }
scanf("%s",s.dob); printf("The bonacci series is: \n"); printf("Enter name: "); if(decision==0) {
printf("\nDisplaying Information\n"); bonacciSeries(range); scanf("%s",s[i].name); printf("The search element is not present");
printf("Name: %s\n",s.name); return 0; printf("Enter price: "); }
printf("Address: %s\n",s.address); } scanf("%d",&s[i].price); else if(decision>1) {
printf("Date of birth: %s\n",s.dob); Concatenate Two Strings printf("Enter quantity: "); printf("The search element is present, %d
return 0; #include <stdio.h> scanf("%d", &s[i].quantity); times.",decision+1);
} int main() { } }
Reverse a number char s1[100] = "programming ", s2[] = "is printf("Displaying Information:\n\n"); }
#include <stdio.h> awesome"; for (i = 0; i < 2; ++i) {
int main() { int length, j; printf("\nProduct number: %d\n", i + 1);
int n, reverse = 0, remainder; length = 0; printf("Product Name: ");
printf("Enter an integer: "); while (s1[length] != '\0') { puts(s[i].name);
scanf("%d", &n); ++length; printf("Product quantity: %d",s[i].quantity);
while (n != 0) { } printf("Product price: %d", s[i].price);
remainder = n % 10; for (j = 0; s2[j] != '\0'; ++j, ++length) { printf("\n");
reverse = reverse * 10 + remainder; s1[length] = s2[j]; pp=s[i].price*s[i].quantity;
n /= 10; } tp=tp+pp;
} s1[length] = '\0'; }
printf("Reversed number = %d", reverse); printf("After concatenation: "); printf("\n");
return 0; puts(s1); printf("Total price in %d",tp);
} return 0; return 0;
} }
ff
fi
fi
ff
ff
fi
fi
fi
ff
fi
ffi
fi

You might also like