2
++
: ++.
, . , , . , if goto. , goto . ++ while, do while for.
while :
while ()
, , . while (.1):
1. .
2. , while . , while.
3. 1.
while , while , , .
, , .
int Sum=0, x; // Sum , x
//
cin>>x; //
while (x!=0) // x , : while(x)
{
Sum+=x; //
cin>>x; //
}
cout<<Sum; //
, . .
do while
do while , . :
do {} while ();
do while (.2):
1. ( ).
|
|
2. .
3. , do while . , 1.
do while.
int Sum=0, x; // Sum , x
//
do
{
cin>>x; //
Sum+=x; //
}
while (x!=0) // x , : while(x)
cout<<Sum; //
, , . .
while do while .
:
int i,j,k;
...
i=0; j=0; k=0;
do { i++;
j--;
while (a[k] < i) k++;
}
while (i<30 && j<-30);
for ++. :
for ( 1; 2; 3)
1 , . , . 2 - , , . 3 , . , .
for (.3):
1. 1.
2. 2.
3. 2 (), ( , ), 3 2, 2 (), , for.
for ( 1; 2; 3) ; while :
1;
while ( 2)
{ ;
3;
}
, . , , for while. for :
int x, Sum;
cin >> x; //
for (Sum = 0; x!=0;)
(
Sum += x; //
cin >> x; //
}
cout << Sum; //
for , . .
int i,b;
for (i=1; i<10; i++)
cout<<i<<^2=<<i*i<<endl;;
1 9. i , 1 for, ( 1) 3, 2. ,
|
|
for (c_=_; _ < _+1; _+=_)
++ . , ( ) for : , , , 1 -1.
for , .
:
int main()
{ int top, bot;
char string[100], temp;
for (top=0, bot=100; top < bot; top++, bot--)
{ temp=string[top];
string[bot]=temp;
}
return 0;
}
, , top bot. , 1 3 , , .
for 3 . .
unsigned int n, f;
cin >> n;
for (unsigned int i=2, f=1; i<=n; f*=i++);
cout << f;
, ( , ) for.
for.
for (i=0; t[i]<=10; i++);
i t, 10.
for . , break. :
for (;;)
{...
if ( ) break;
...
}
break . break switch, do while, for, while. break , .
continue , break , , 3 for .
, 20 .
int pr=1, val, i;
for (i=1; i<=20; i++) // 20
{
cin >> val; //
if (val==1) continue; //
if (val==0) // 0
{pr=0;break;} // ,
pr*=val; //
}
cout << pr; //
, . , .
, break continue , , , . , , :
|
|
int pr=1, val, i;
for (i=1; i<=20 && pr!=0; i++) // 20 , // 0
//
{
cin >> val; //
if (val!=1) //
pr*=val; //
}
cout << pr; //
1. ++ ?
2. - ?
3. for while?
4. / ?
5. ?
6. * , ?
1. ++ .
2. .
3. , .
4. , .
5. .
6. .
7. .
:
- ;
- ;
- ;
- ;
- ;
- .
:
11 ()
1. n . , n . .
#include <math.h>
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP (1251);
int x=0,c=0,n=4,first,otric=0,bol=0,i;
system(cls);
cout<<" 1-oe : ";
cin>>first;
if (first<0) otric++;
for (i=2;i<=n;i++)
{
cout<<" "<<i<<"-oe : ";
cin>>x;
if (x<0) otric++;
if (x>first) bol++;
}
cout<<" :"<<otric<<"\n";
cout<<" , : "<<bol;
system(pause);
return 0;
}
. , 3.
#include <math.h>
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP (1251);
int x,c,n,i,count=0;
system(cls);
do
{
cout<<" : ";
cin>>x;
c=x%100;
n=c/10;
i=c%10;
if (x>9 && n%3==0 && i%3==0) count++;
}
while(x!=0);
cout<<" : "<<count;
system(puase);
return 0;
}
1
1. n . , n . .
2. . .
|
|
2
1. , . , .
2. . .
3
1. . , . , .
2. . , 5.
4
1. 0. , 20, 100 3.
2. . , 3.