You are on page 1of 4

Name: Adeleye kolade kayode

Department: computer science

Matric num: csc/2020/1013

Csc 315 assignment

Solution

Question 1

#include<stdio.h>

int main(){

char Examination[50];

intlength;

length=strlen(Examination);

printf("The length of the string 'Examination' is %d.\n",length);

return0;

Question 2

#include <stdio.h>

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

int temp = *a;

*a = *b;

*b = temp;

void bubbleSort(int *arr, int size) {

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


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

if (*(arr + j) > *(arr + j + 1)) {

swap(arr + j, arr + j + 1);

void printArray(int *arr, int size) {

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

printf("%d ", *(arr + i));

printf("\n");

int main() {

int arr[] = { 13, 22, 7, 12, 4 };

int size = sizeof(arr) / sizeof(arr[0]);

printf("Original array: ");

printArray(arr, size);

bubbleSort(arr, size);

printf("Sorted array: ");

printArray(arr, size)

return 0;

Question 3
#include<stdio.h>

int main()

intn=5;

for(inti=1;i<=n;i++){

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

printf("");

intx=1;

for(intj=1;j<=i;j++){

printf("%d ",x);

x=x*(i-j)/j;

printf("\n");

return0;

}3

Output: number

1 1

1 2 1

1 3 3 1

1 4 6 4 1

Question 4
#include <stdio.h>

#include <string.h>

int isPalindrome(char *string) {

int length = strlen(string);

int i;

for (i = 0; i < length / 2; i++) {

if (string[i] != string[length - i - 1]) {

return 0;

return 1;

int main() {

char string[] = "madam";

if (isPalindrome(string)) {

printf("The string is a palindrome.\n");

} else {

printf("The string is not a palindrome.\n");

return 0;

You might also like