loops - Program for this Alphabet pattern in c++ -
Is there any other way to do this program with less loops? It is not very efficient
#include & lt; Iostream & gt; using namespace std; Int main () {int i, j, n, s; Cout & lt; & Lt; "Enter the value of n"; CIN & gt; & Gt; N; For (i = 1; i & lt; = n; i ++) {for (s = 1; s & lt; = n-i; s ++) {cout & lt; & Lt; ""; } Four f = 97; Int k = 1; For (j = 1; j & lt; = (i * 2-1); j ++) {if (k% 2! = 0) {cout & lt; & Lt; Ch; Ch ++; } And {cout & lt; & Lt; ""; } K ++; } Cout & lt; & Lt; Endl; }}
Output:
n6 aababcabcdabcdeabcdef
Try the following code -
Add # & lt; Stdio.h & gt; Main () {int i, j, k, num; Printf ("Enter the number of characters \ n"); Scanf ("% d", and number); For (i = 0; i
Sample input and output -
sathish @ Ubuntu: ~ / c / basics $ ./a.out Number of characters 4 Enter the abac
Comments
Post a Comment