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

FOP Problemsheet 4 1

The document contains a problem sheet with five programming tasks in C. The tasks include counting odd numbers in an array, sorting five numbers in ascending order, finding the transpose of a 3x3 matrix, converting a word to uppercase, and reversing a word. Each task is accompanied by a complete C program implementation.

Uploaded by

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

FOP Problemsheet 4 1

The document contains a problem sheet with five programming tasks in C. The tasks include counting odd numbers in an array, sorting five numbers in ascending order, finding the transpose of a 3x3 matrix, converting a word to uppercase, and reversing a word. Each task is accompanied by a complete C program implementation.

Uploaded by

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

PROBLEMSHEET - 4

1. Write a program that will accept an array of 10 numbers and count of odd
numbers from the array

#include <stdio.h>
#include<conio.h>
int main()
{
int numbers[10];
int countOdd = 0;
int i;
printf("Enter 10 numbers:\n");
for (i = 0; i < 10; i++)
{
printf("Number %d: ", i + 1);
scanf("%d", &numbers[i]);
}
for (i = 0; i < 10; i++)
{
if (numbers[i] % 2 != 0)
{
countOdd++;
}
}
printf("Count of odd numbers: %d\n", countOdd);
return 0;
}

Page | 1
PROBLEMSHEET - 4

2. Write a program to sort 5 numbers in ascending order.

#include <stdio.h>
#include<conio.h>
int main()
{
int numbers[5];
int i, j, temp;
printf("Enter 5 numbers:\n");
for (i = 0; i < 5; i++)
{
printf("Number %d: ", i + 1);
scanf("%d", &numbers[i]);
}
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4 - i; j++)
{
if (numbers[j] > numbers[j + 1])
{
temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}

Page | 2
PROBLEMSHEET - 4

printf("Numbers in ascending order:\n");


for (i = 0; i < 5; i++)
{
printf("%d ", numbers[i]);
}
printf("\n");
return 0;
}

Page | 3
PROBLEMSHEET - 4

3. Write a program to read 3X3 matrix and find the transpose of matrix.

#include <stdio.h>
#include<conio.h>
int main()
{
int matrix[3][3];
int transpose[3][3];
int i, j;
printf("Enter the elements of the 3x3 matrix:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("Element [%d][%d]: ", i + 1, j + 1);
scanf("%d", &matrix[i][j]);
}
}

for (i = 0; i < 3; i++)


{
for (j = 0; j < 3; j++)
{
transpose[j][i] = matrix[i][j];
}

Page | 4
PROBLEMSHEET - 4

printf("\nOriginal Matrix:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}

printf("\nTranspose of the Matrix:\n");


for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}

Page | 5
PROBLEMSHEET - 4

4. Write a program to read a word and convert it to upper case.

#include <stdio.h>
#include <conio.h>
int main()
{
char word[100];
int i;
printf("Enter a word: ");
scanf("%s", word);
for (i = 0; word[i] != '\0'; i++)
{
word[i] = toupper(word[i]);
}
printf("Word in uppercase: %s\n", word);
return 0;
}

Page | 6
PROBLEMSHEET - 4

5. Write a program to read a word and convert it to reverse.

#include <stdio.h>
#include <conio.h>
int main()
{
char word[100];
int length, i;
printf("Enter a word: ");
scanf("%s", word);

length = strlen(word);

printf("Reversed word: ");


for (i = length - 1; i >= 0; i--)
{
putchar(word[i]);
}
printf("\n");
return 0;
}

Page | 7

You might also like