Computer Science, asked by ajay5988, 6 months ago

write a program to take 10 names and print only those names whose ASCII sum is more than 500​

Answers

Answered by dipakghi1
0

Program to find the largest and smallest ASCII valued characters in a string

Given a string of lower case and uppercase characters, your task is to find the largest and smallest alphabet (according to ASCII values) in the string. Note that in ASCII, all capital letters come before all small letters.

Examples :

Input : sample string

Output : Largest = t, Smallest = a

Input : Geeks

Output : Largest = s, Smallest = G

Explanation: According to alphabetical order

largest alphabet in this string is 's'

and smallest alphabet in this string is

'G'( not 'e' according to the ASCII value)

Input : geEks

Output : Largest = s, Smallest = E

The maximum possible value can be ‘z’ and smallest possible value can be ‘A’.

// C++ program to find largest and smallest

// characters in a string.

#include <iostream>

using namespace std;

// function that return the largest alphabet.

char largest_alphabet(char a[], int n)

{

// initializing max alphabet to 'a'

char max = 'A';

// find largest alphabet

for (int i=0; i<n; i++)

if (a[i] > max)

max = a[i];

// returning largest element

return max;

}

// function that return the smallest alphabet

char smallest_alphabet(char a[], int n)

{

// initializing smallest alphabet to 'z'

char min = 'z';

// find smallest alphabet

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

if (a[i] < min)

min = a[i];

// returning smallest alphabet

return min;

}

// Driver Code

int main()

{

// Character array

char a[]= "GeEksforGeeks";

// Calculating size of the string

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

// calling functions and print returned value

cout << "Largest and smallest alphabet is : ";

cout << largest_alphabet(a,size)<< " and ";

cout << smallest_alphabet(a,size)<<endl;

return 0;

}

Similar questions