0% found this document useful (0 votes)
57 views2 pages

Sting Pairs

This C program contains functions to count vowels in a string and find pairs of numbers in an array that sum to a given value. It takes in an array of numbers, counts the vowels in the string representations of each number, and uses this vowel count to find the number of pairs in the array that sum to this value. It returns the pair count as a string.
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)
57 views2 pages

Sting Pairs

This C program contains functions to count vowels in a string and find pairs of numbers in an array that sum to a given value. It takes in an array of numbers, counts the vowels in the string representations of each number, and uses this vowel count to find the number of pairs in the array that sum to this value. It returns the pair count as a string.
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/ 2

// Sting Pairs

#include<stdio.h>
int countVowels(char str[]){
int i,v=0;
for(i=0;str[i]!='\0';i++){
if(str[i]=='a' || str[i]=='e'|| str[i]=='i' || str[i]=='o' ||
str[i]=='u'){
v++;
}
}
return v;
}

int printPairs(int arr[], int n, int sum)


{
int count = 0, i,j;
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (arr[i] + arr[j] == sum)
count++;
return count;
}

int main(){
char *single_digits[] = { "zero", "one", "two", "three",
"four","five", "six", "seven", "eight", "nine"};
char *two_digits[] = {"", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
char *tens_multiple[] = {"", "", "twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety"};
char str[20];
int a[100],i,n,nov=0, num, nopairs;

scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}

for(i=0;i<n;i++){
num = a[i];
if(num==100){
nov = nov + countVowels("hundred");
}
else if (num <=10) {
nov = nov + countVowels(single_digits[num]);
}
else if(num>10 && num<=19) {
nov = nov + countVowels(two_digits[num]);
}
else {
nov = nov + countVowels(single_digits[num%10]);
nov = nov + countVowels(tens_multiple[num/10]);
}
}
nopairs = printPairs(a, n, nov);
printf("%s",single_digits[nopairs]);
}

You might also like