Showing posts with label nested loop. Show all posts
Showing posts with label nested loop. Show all posts

Wednesday, February 3, 2016

Write C++ Program to draw up side down right angle triangle using alphabets

Leave a Comment
Questions:

Write C++ Program to draw up side down right angle triangle using alphabets

Explanation:

This C++ Program is examples of nested loop.Below mention code is compiled in Visual Studio 2015 and output snap is attached.. If any problem you feel and want explanation feel free to contact.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/
#include<iostream>
using namespace std;
void main() {
       int value = 0;
       cout << "Enter Value for the size of Triangle = ";
       cin >> value;
       int temp = value;
       for (int i = 0; i < value; i++) {
              for (int space = 0; space < i; space++) {
                     cout << " ";
              }
              for (int counting = 0; counting < temp; counting++) {
                     cout <<char(temp+64);
              }
              temp--;
              cout << endl;
       }


}

Output:





Related Articles:

C++ Shapes Codes
Read More

Friday, August 7, 2015

Left Triangle pattern using Capital Alphabet single in on line

Leave a Comment
Questions:

Left Triangle pattern using Capital Alphabet single in on line

Code:

#include<iostream>
using namespace std;
void main()
{

//Left Triangle pattern using Capital Alphabet single in on line
int square,space=0;
cout<<"Enter The Size of Square = "; // size
cin>>square;
space=square;
for(int i=1;i<=square;i++)
{
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int l=1;l<=i;l++)
{
cout<<char(l+64);
}
cout<<endl;
space--;
}

}


Output


Read More

Left Triangle pattern using Capital Alphabet single in on line

Leave a Comment
Questions:

Left Triangle pattern using Capital Alphabet single in on line

Code:

#include<iostream>
using namespace std;
void main()
{

//Left Triangle pattern using Capital Alphabet single in on line
int square,space=0;
cout<<"Enter The Size of Square = "; // size
cin>>square;
space=square;
for(int i=1;i<=square;i++)
{
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int l=1;l<=i;l++)
{
cout<<char(i+64);
}
cout<<endl;
space--;
}

}


Output


Read More

Left Triangle pattern using Numerical digits

Leave a Comment
Questions:

Left Triangle pattern using Numerical digits

Code:

#include<iostream>
using namespace std;
void main()
{

//Left Triangle pattern using Numerical digits
int square,space=0;
cout<<"Enter The Size of Square = "; // size
cin>>square;
space=square;
for(int i=1;i<=square;i++)
{
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int l=1;l<=i;l++)
{
cout<<l;
}
cout<<endl;
space--;
}

}


Output


Read More

Left Triangle pattern using Numerical digits

Leave a Comment
Questions:

Left Triangle pattern using Numerical digits

Code:

#include<iostream>
using namespace std;
void main()
{

//Left Triangle pattern using Numerical digits
int square,space=0;
cout<<"Enter The Size of Square = "; // size
cin>>square;
space=square;
for(int i=1;i<=square;i++)
{
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int l=1;l<=i;l++)
{
cout<<i;
}
cout<<endl;
space--;
}

}


Output


Read More

Left Triangle pattern using stars

Leave a Comment
Questions:

Left Triangle pattern using stars

Code:

#include<iostream>
using namespace std;
void main()
{

//Left Triangle pattern using stars
int square,space=0;
cout<<"Enter The Size of Square = "; // size
cin>>square;
space=square;
for(int i=1;i<=square;i++)
{
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int l=1;l<=i;l++)
{
cout<<"*";
}
cout<<endl;
space--;
}

}


Output

Read More

Right Triangle pattern using capital alphabets E D C B A

Leave a Comment
Questions:

Right Triangle pattern using capital alphabets E D C B A

Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using capital alphabets E D C B A
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=square;j>=i;j--) //inner loop
{
cout<<char(j+64)<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output

Read More

Right Triangle pattern using capital Alphabets

Leave a Comment
Questions:

Right Triangle pattern using capital Alphabets

Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using capital Alphabets
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<char(i+64)<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output


Read More

Right Triangle pattern using numerical digits

Leave a Comment
Questions:

Right Triangle pattern using numerical digits
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using numerical digits
//5 4 3 2 1
//5 4 3 2
//5 4 3
//5 4
//5

int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=square;j>=i;j--) //inner loop
{
cout<<j<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output


Read More

Right Triangle pattern using numerical digits

Leave a Comment
Questions:

Right Triangle pattern using numerical digits
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using numerical digits
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<i<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output

Read More

Friday, July 24, 2015

C++ Program to Solve the Magic Squares Puzzle without using Recursion

Leave a Comment
The following C++ program, using iteration, finds the magic square for a given odd sized number. A magic square is an arrangement of numbers from 1 to n^2 in an [n x n] matrix, with each number occurring exactly once, and such that the sum of the entries of any row, any column, or any main diagonal is the same.


Code:

#include<iostream>
using namespace std;

void magicsq(int, int [][10]);

int main( )
{
    int size;
    int a[10][10];

    cout<<"Enter the size: ";
    cin>>size;
    if (size % 2 == 0)
    {
        cout<<"Magic square works for an odd numbered size\n";
    }
    else
    {
        magicsq(size, a);
    }
    return 0;
}

void magicsq(int size, int a[][10])
{
    int sqr = size * size;
    int i = 0, j = size / 2, k;

    for (k = 1; k <= sqr; ++k)
    {
        a[i][j] = k;
        i--;
        j++;

        if (k % size == 0)
        {
            i += 2;
            --j;
        }
        else
        {
            if (j == size)
            {
                j -= size;
            }
            else if (i < 0)
            {
                i += size;
            }
        }
    }
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
        {
            cout<< a[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
}

Output:

Read More

Thursday, March 19, 2015

Right Triangle pattern using Capital in reverse triangle order

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Capital in reverse triangle order
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<char(i+64)<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output


Read More

Right Triangle pattern using Numeric in reverse order

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Numeric in reverse order
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<j<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output



Read More

Right Triangle pattern using Numeric single digit in one line in reverse order

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Numeric single digit in one line in reverse order
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<i<<" "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output


Read More

Right Triangle pattern using asterisk in reverse order

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using asterisk in reverse order
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = square;i>=1;i--) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<"* "; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output


Read More

Right Triangle pattern using Capital Alphabets

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Capital Alphabets
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<char(j+64); // value that is output
}
cout<<endl;//new line for next line output
}

}


Output

Read More

Right Triangle pattern using Capital Alphabet single in one line

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Capital Alphabet single in one line
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<char(i+64); // value that is output
}
cout<<endl;//new line for next line output
}

}


Output

Read More

Right Triangle pattern using Numeric digits

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Numeric digits
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<j; // value that is output
}
cout<<endl;//new line for next line output
}

}


Output


Read More

Right Triangle pattern using Numeric single digit in one line

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using Numeric single digit in one line
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<i; // value that is output
}
cout<<endl;//new line for next line output
}

}

Output

Read More

Right Triangle pattern using asterisks

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
//Right Triangle pattern using asterisks
int square;
cout<<"Enter The Size of Square = "; // size
cin>>square;
for(int i = 1;i<=square;i++) // outer loop
{
for(int j=1;j<=i;j++) //inner loop
{
cout<<"*"; // value that is output
}
cout<<endl;//new line for next line output
}

}



Output

                         
Read More