Professional Documents
Culture Documents
Loop Ideas
Loop Ideas
Loop Ideas
Idea code
cout << "enter N: ";
Print numbers from N to cin >> N;
M, cout << "enter M: ";
ascending (N to M) or cin >> M;
descending (M to N) for(int i=N;i<=M;i++)
cout << i << ", ";
cout << "enter N: ";
cin >> N;
Print Odd/Even numbers
cout << "enter M: ";
from N to M,
cin >> M;
ascending (N to M) or
for(int i=N;i<=M;i++)
descending (M to N)
if(i%2==0)//if even
cout << i << ", ";
sum=0;
mult=1;
counter=0;
AP SERIES next=first;
cout << "AP SERIES: ";
while(terms!=0)
{
cout << next << " ";
next+=difference;
terms--;
}
dig=0, op=0, com=0,bows=0,other=0;
flag=true;
cout<<"Enter Formula: ";
while(flag )
{
cout << in<<endl;
switch(in)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
dig++;
break;
case '+':
case '-':
A program that allows
case '*':
entering a mathematical
case '/':
equation and then
case '^':
enumerates everything
case '%':
that is used in the
op++;
equation from numbers,
break;
operations, and
case '>':
parentheses...
case '<':
case '=':
com++;
break;
case '(':
case ')':
bows++;
break;
case '#':
break;
default:
other++;
break;
}
if(in == '#')
flag = false;
}
cout << dig << " digits\n";
cout << op << " operators\n";
cout << com << " comparisons\n";
cout << bows << " bows\n";
cout << other << " others\n";
do
{
cout << "\n**Menu**\n";
Display menu until exit cout << "Welcome to CCSIT in KFU\n\n";
choice cout << "To Continue Press Any Key ,, To Exit Press 'N': ";
cin >> choice;
}while(choice!='n' && choice!='N');
cout << "**Good Byeee**";
for(int i=1;i<=10;i++)
{
Print the number table for(int j=1;j<=10;j++)
from 1 to 10 cout << i<<"*"<<j<<"="<<i*j<<"\t";
cout<<endl;
}
cout << "enter N: ";
cin >> N;
cout << "enter M: ";
cin >> M;
for(int i=N;i<=M;i++)
{
if(i==1)
cout << 1 << ", ";
Primary Numbers from N else
to M {
iCounter=0;
for(int j=1;j<=i;j++)
if(i%j==0)
iCounter++;
if(iCounter==2)
cout << i <<", ";
}
}
Print shapes
for(int r=1;r<=3;r++)
{
***
for(int c=1;c<=3;c++)
***
cout << "*";
***
cout<<endl;
}
for(int r=1;r<=3;r++)
{
*
for(int c=1;c<=r;c++)
**
cout << "*";
***
cout<<endl;
}
for(int r=1;r<=3;r++)
{
***
for(int c=r;c<=3;c++)
**
cout << "*";
*
cout<<endl;
}
for(int r=1;r<=3;r++)
{
for(int c=r;c<=2;c++)
*
cout << " ";
**
for(int c=1;c<=r;c++)
***
cout << "*";
cout<<endl;
}
for(int r=1;r<=3;r++)
{
for(int c=r;c<=2;c++)
*
cout << " ";
***
for(int c=1;c<=r*2-1;c++)
*****
cout << "*";
cout<<endl;
}
for(int r=1;r<=3;r++)
{
for(int c=r;c<=2;c++)
cout << " ";
for(int c=1;c<=r*2-1;c++)
cout << "*";
*
cout<<endl;
***
}
*****
for(int r=2;r>=1;r--)
***
{
*
for(int c=r;c<=2;c++)
cout << " ";
for(int c=1;c<=r*2-1;c++)
cout << "*";
cout<<endl;
}