Function with no return values Write a C program for 6 II Di
Function with no return values:
Write a C++ program for
Solution
Program Code:
#include <iostream>
using namespace std;
void printChars(char ch1, char ch2, int numberPerLine)
{
char letter1 = ch1;
char letter2 = ch2+1; // incrementing to the next letter
int counter = 1; // counter for counting the characters printed
while(letter1 != letter2) // checking till ch1 is not equal to ch2
{
if(counter<numberPerLine)
{
cout<<letter1<<\" \"; // printing with one space when the counter is less than numberPerLine
}
else
{
cout<<letter1<<\"\ \"; //printing a new line when the numberPerLine is reached.
counter = 0;
}
letter1 = letter1 + 1; // incrementing the letter with one. This moves to the next character in the alphabetical order.
counter++;
}
cout<<\"\ \ \";
}
int main() {
// All uppercase letters using 6 characters perline
cout<<\"All letters in lowercase\ \ \";
printChars(\'a\', \'z\', 6);
// All lowercase letters using 8 characters per line
cout<<\"All letters in uppercase\ \ \";
printChars(\'A\', \'Z\', 8);
// All charcaters between \'l\' and \'Z\' using 10 characters per line
cout<<\"All letters between \'l\' and \'z\'\ \ \";
printChars(\'l\', \'z\', 10);
return 0;
}
OUTPUT:
