Loop Examples
Loop Examples
# include <iostream>
using namespace std;
void main()
{
float num,sum=0,avg,Max=0,Min=99999;
if(num >Max)
Max=num;
if(num <Min)
Min=num;
}
avg=sum/10;
cout<<" average"<<avg <<endl;
cout<<" Max="<<Max<<endl ;
cout<<" Min="<<Min ;
system("pause");
}
# include <iostream>
void main()
{ int a,sumodd=0,sumeven=0;
cout<< " please enter num";
for(int i=0;i<10;i++)
{
cin>>a;
if((a%2)==0)
sumeven+=a;
else
sumodd+=a;
}
1
cout<<" sumeven"<<sumeven;
cout<<" sumodd="<<sumodd ;
system("pause");
}
# include <iostream>
using namespace std;
void main()
{
char m;
cout<<"please enter chararter";
cin>>m;
while(m != 'z')
{
cout<<m;
cin>>m;
}
system("pause");
}
#include <iostream>
using namespace std;
void main ()
{
int f=1,a;
for(int i=a;i>=1;i--)
{
f*=i;
}
cout<<"factorial="<<f;
system("pause");
2
5. Write a program to compute the differentiation equation.
The program will read the coefficient, the power and the
variable. Then display the given equation and the equation
after it differentiates.
Example: 2X4
=>8X3
#include <iostream>
using namespace std;
void main ()
{
int p,c;
for(int i=p;i>=1;i--)
{
cout<<c<<"X"<<i<<endl;
c*=i;
}
system("pause");
He will enter the information for each trip during his day.
NOTE: the deriver will stop the program when he got total
# include <iostream>
3
using namespace std;
void main()
{
float income,distance, tincome=0,tdistance=0,
shortest=99999;
int count=0;
}
cout<< " how many trips he made is"<< count ;
cout<<" the total distance"<<tdistance ;
cout<<" the shortest trip"<<shortest ;
system("pause");
}