/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
1. Write a user define function in C to print all unique elements in an array.
*/
#include <stdio.h>
int main()
int n,i,q;
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(i=0;i<n;i++)
printf("element - %d: ",i);
scanf("%d",&q);
a[i]=q;
for(i=0;i<n;i++)
printf("The unique elements found in the array are: %d %d\n",i,a[i]);
return 0;
Input:
Input the number of elements to be stored in the array: 3
Input 3 elements in the array:
element - 0: 4
element - 1: 5
element - 2: 6
Output:
The unique elements found in the array are: 0 4
The unique elements found in the array are: 1 5
The unique elements found in the array are: 2 6
/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
2. Write a program in C to separate odd and even integers into separate arrays.
*/
#include <stdio.h>
int main()
int n,i,q;
printf("Input the number of elements to be stored in the array: ");
scanf("%d",&n);
int a[n],o[n],e[n],j=0,k=0;
printf("Input %d elements in the array: \n",n);
for(i=0;i<n;i++)
printf("element - %d: ",i);
scanf("%d",&q);
a[i]=q;
printf("The Even elements are: ");
for(i=0;i<n;i++)
if(a[i]%2==0)
printf("%d ",a[i]);
printf("\nThe odd elements are: ");
for(i=0;i<n;i++)
{
if(a[i]%2!=0)
printf("%d ",a[i]);
return 0;
Input:
Input the number of elements to be stored in the array: 5
Input 5 elements in the array:
element - 0: 1
element - 1: 2
element - 2: 3
element - 3: 7
element - 4: 8
Output:
The Even elements are: 2 8
The odd elements are: 1 3 7
/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
3. Write a program in C to find the sum of the lower triangular elements of a matrix.
*/
#include <stdio.h>
int main() {
int r, c;
printf("Enter the number of rows for the matrix: ");
scanf("%d", &r);
printf("Enter the number of columns for the matrix: ");
scanf("%d", &c);
int m[r][c];
int sum = 0;
printf("Enter the elements of the %dx%d matrix:\n", r, c);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &m[i][j]);
printf("The given array is:\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
printf("%d ", m[i][j]);
printf("\n");
printf("The elements being summed of the lower triangular matrix are: ");
for (int i = 1; i < r; i++) {
for (int j = 0; j < i && j < c; j++) {
printf("%d ", m[i][j]);
sum += m[i][j];
printf("\nThe Sum of the lower triangular Matrix Elements are: %d\n", sum);
return 0;
Input:
Enter the number of rows for the matrix: 3
Enter the number of columns for the matrix: 3
Enter the elements of the 3x3 matrix:
234567436
Output:
The given array is:
234
567
436
The elements being summed of the lower triangular matrix are: 5 4 3
The Sum of the lower triangular Matrix Elements are: 12
/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
4. Write a program in C to find the max element of each row of a matrix.
*/
#include <stdio.h>
int main() {
int r, c;
printf("Enter the number of rows for the matrix: ");
scanf("%d", &r);
printf("Enter the number of columns for the matrix: ");
scanf("%d", &c);
int m[r][c];
printf("Enter the elements of the %dx%d matrix:\n", r, c);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &m[i][j]);
printf("The given array is:\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
printf("%d ", m[i][j]);
printf("\n");
}
int max;
printf("\nThe maximum element of each row of matrix are: ");
for (int i = 0; i < r; i++)
max=m[i][0];
for (int j = 1; j < c; j++)
if(m[i][j]>max)
max=m[i][j];
printf("%d ",max);
return 0;
Input:
Enter the number of rows for the matrix: 3
Enter the number of columns for the matrix: 3
Enter the elements of the 3x3 matrix:
369
793
753
Output:
The given array is:
369
793
753
The maximum element of each row of matrix are: 9 9 7
/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
5. Write a program in C to split string by space into words.
*/
#include <stdio.h>
int main()
char a[100];
int i;
gets(a);
printf("Strings or words after split by space are: \n");
for(i=0;a[i]!='\0';i++)
if(a[i]==' ')
printf("\n");
else
printf("%c",a[i]);
Input:
hi this is a test case
Output:
Strings or words after split by space are:
hi
this
is
test
case
/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
6. Write a user define function to find the highest frequency character in a string.
*/
#include <stdio.h>
int main()
char str[100]={0};
int i;
gets(str);
int frequency[256];
for (int i = 0;str[i]!='\0'; i++)
frequency[(int)str[i]]++;
char hghCh;
int hghFr = 0;
for (int i = 0; i < 256; i++) {
if (frequency[i] > hghFr)
hghFr = frequency[i];
hghCh = (char)i;
printf("Highest frequency character appears in a string is %c.\n", hghCh);
return 0;
}
Input:
hi i am a hacker
Output:
Highest frequency character appears in a string is a.
/*
Name: Saniya Nainwal
University Roll no. : 2023097
Section: H
7. Write a program to remove characters from a string except alphabets
*/
#include <stdio.h>
int main()
char a[100],b[100];
int i,j=0;
gets(a);
for(i=0;a[i]!='\0';i++)
if((a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= 'a' && a[i] <= 'z'))
b[j]=a[i];
j++;
printf("%s",b);
Input:
jsoi983j3^*jcdoi
Output:
jsoijjcdoi