From b0d1386f3495b170519785839e51e2c4c3623b98 Mon Sep 17 00:00:00 2001 From: shank1729 <104124777+shank1729@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:07:51 +0530 Subject: [PATCH] codes added --- ARRAY Problems/LargestElementinArray.c | 36 ++++++++++++++++++++++++++ String Problems/Totalvowelconsonants.c | 35 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 ARRAY Problems/LargestElementinArray.c create mode 100644 String Problems/Totalvowelconsonants.c diff --git a/ARRAY Problems/LargestElementinArray.c b/ARRAY Problems/LargestElementinArray.c new file mode 100644 index 0000000..37d0ac3 --- /dev/null +++ b/ARRAY Problems/LargestElementinArray.c @@ -0,0 +1,36 @@ +/* + * C Program to find the largest number in an array using loops + */ + +#include + +int main() +{ + int size, i, largest; + + printf("\n Enter the size of the array: "); + scanf("%d", &size); + int array[size]; //Declaring array + + //Input array elements + + printf("\n Enter %d elements of the array: \n", size); + + for (i = 0; i < size; i++) + { + scanf(" %d", &array[i]); + } + + //Declaring Largest element as the first element + largest = array[0]; + + for (i = 1; i < size; i++) + { + if (largest < array[i]) + largest = array[i]; + } + + printf("\n largest element present in the given array is : %d", largest); + + return 0; + } \ No newline at end of file diff --git a/String Problems/Totalvowelconsonants.c b/String Problems/Totalvowelconsonants.c new file mode 100644 index 0000000..94642ee --- /dev/null +++ b/String Problems/Totalvowelconsonants.c @@ -0,0 +1,35 @@ +#include +#include +#include + +#define str_size 100 //Declare the maximum size of the string + +void main() +{ + char str[str_size]; + int i, len, vowel, cons; + + printf("\n\nCount total number of vowel or consonant :\n"); + printf("----------------------------------------------\n"); + printf("Input the string : "); + fgets(str, sizeof str, stdin); + + vowel = 0; + cons = 0; + len = strlen(str); + + for(i=0; i='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z')) + { + cons++; + } + } + printf("\nThe total number of vowel in the string is : %d\n", vowel); + printf("The total number of consonant in the string is : %d\n\n", cons); +} \ No newline at end of file