0% found this document useful (0 votes)
37 views5 pages

Loop Ideas

Uploaded by

2qkcr77pvd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Loop Ideas

Uploaded by

2qkcr77pvd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Simple and nested loop

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;

cout << "enter N: ";


cin >> N;
cout << "enter M: ";
Find then Display the Sum, cin >> M;
multiply and average (Odd for(int i=N;i<=M;i++)
or Even) numbers from N if(i%2!=0)//if odd
to M {
counter++;
sum+=i;
mult*=i;
}
cout << "sum: "<<sum<<endl;
cout << "multi: "<<mult<<endl;
cout << "avg: "<<sum/counter<<endl;
Fact=1;

Find then Display the cout << "enter N: ";


Factorial (N!) cin >> N;
5!=5*4*3*2*1=120 for(int i=1;i<=N;i++)
Fact*=i;
cout << N <<"! is : "<<Fact;
sum=0;

cout << "enter N: ";


Find then Display the cin >> N;
Summation or temp=N;
multiplication of the digits do
that make up the number {
N sum+=temp%10;
temp/=10;
}while(temp!=0);
cout << "sum of digits that make up the number "<<N<<" is : "<<sum;
reverse=0;
cout << "enter N: ";
cin >> N;
temp=N;
do
Reverse Number
{
reverse=(reverse*10)+temp%10;
temp/=10;
}while(temp!=0);
cout << "the reverse of "<<N<<" is : "<<reverse;
cout << "enter N: ";
cin >> N;
cout << "enter Number1: ";
cin >> Number;
Min=Max=Number;
for(int i=2;i<=N;i++)
Find then Display The {
largest and lowest number cout << "enter Number"<<i<<": ";
among 10 numbers (min, cin >> Number;
max) if(Number>Max)
Max=Number;
if(Number<Min)
Min=Number;
}
cout << "Max is : "<<Max<<endl;
cout << "Min is : "<<Min<<endl;
Sum=0;

cout << "enter N: ";


cin >> N;
for(int i=1;i<=N;i++)
calculate the summation
{
and the average for N
cout << "enter Number"<<i<<": ";
numbers
cin >> Number;
Sum+=Number;
}
cout << "Sum is : "<<Sum<<endl;
cout << "Average is : "<<Sum/N<<endl;
cout << "enter number of terms: ";
cin >> terms;
cout << "enter first term: ";
cin >> first;
cout << "enter common difference of AP: ";
cin >> difference;

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;
}

You might also like