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:

Enter the value of 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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -