- #include <iostream>
- using namespace std;
- int main()
- {
- int a[10];
- int i;
- for(i=0;i<10;i++)
- a[i]=i*2+2;
- for(i=0;i<10;i++)
- {
- cout<<a[i]<<'\t';
- if((i+1)%5==0)
- cout<<endl;
- }
- return 0;
- }
#include <iostream>
using namespace std;
int main()
{
int a[10];
int i;
for(i=0;i<10;i++)
a[i]=i*2+2;
for(i=0;i<10;i++)
{
cout<<a[i]<<'\t';
if((i+1)%5==0)
cout<<endl;
}
return 0;
}
- #include <iostream>
- using namespace std;
- int main()
- {
- int i,math[40],n;
- float aver=0.0;
- int unpassedcount=0;
- int highpassedcount=0;
- cout<<"请输入学生人数:";
- cin>>n;
- cout<<"请输入成绩:";
- for(i=0;i<n;i++)
- {
- cin>>math[i];
- aver+=math[i];
- }
- aver/=n;
- for(i=0;i<n;i++)
- {
- if(math[i]<60) unpassedcount++;
- if(math[i]>=90) highpassedcount++;
- }
- cout<<"平均分为:"<<aver<<endl;
- cout<<"90分以上人数:"<<highpassedcount<<endl;
- cout<<"不及格人数为:"<<unpassedcount<<endl;
- return 0;
- }
#include <iostream>
using namespace std;
int main()
{
int i,math[40],n;
float aver=0.0;
int unpassedcount=0;
int highpassedcount=0;
cout<<"请输入学生人数:";
cin>>n;
cout<<"请输入成绩:";
for(i=0;i<n;i++)
{
cin>>math[i];
aver+=math[i];
}
aver/=n;
for(i=0;i<n;i++)
{
if(math[i]<60) unpassedcount++;
if(math[i]>=90) highpassedcount++;
}
cout<<"平均分为:"<<aver<<endl;
cout<<"90分以上人数:"<<highpassedcount<<endl;
cout<<"不及格人数为:"<<unpassedcount<<endl;
return 0;
}
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int a[10],i,big;
- cout<<"please input 10 numbers:\n";
- for(i=0;i<10;i++)
- cin>>a[i];
- cout<<"the numbers are:";
- for(i=0;i<10;i++)
- cout<<setw(4)<<a[i];
- cout<<endl;
- big=a[0];
- for(i=1;i<10;i++)
- if(a[i]>big)
- big=a[i];
- cout<<"the big number is:"<<big<<endl;
- return 0;
- }
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a[10],i,big;
cout<<"please input 10 numbers:\n";
for(i=0;i<10;i++)
cin>>a[i];
cout<<"the numbers are:";
for(i=0;i<10;i++)
cout<<setw(4)<<a[i];
cout<<endl;
big=a[0];
for(i=1;i<10;i++)
if(a[i]>big)
big=a[i];
cout<<"the big number is:"<<big<<endl;
return 0;
}
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int a[10];
- int i,j,t;
- cout<<"please input 10 numbers:\n";
- for(i=0;i<10;i++)
- cin>>a[i];
- cout<<"the numbers are:";
- for(i=1;i<10;i++)
- cout<<setw(4)<<a[i];
- cout<<endl;
- for(i=0;i<9;i++)
- for(j=0;j<9-i;j++)
- if(a[j]>a[j+1])
- {t=a[j];a[j]=a[j+1];a[j+1]=t;}
- cout<<"the sorted numbers are:";
- for(i=0;i<10;i++)
- cout<<setw(4)<<a[i];
- cout<<endl;
- return 0;
- }
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a[10];
int i,j,t;
cout<<"please input 10 numbers:\n";
for(i=0;i<10;i++)
cin>>a[i];
cout<<"the numbers are:";
for(i=1;i<10;i++)
cout<<setw(4)<<a[i];
cout<<endl;
for(i=0;i<9;i++)
for(j=0;j<9-i;j++)
if(a[j]>a[j+1])
{t=a[j];a[j]=a[j+1];a[j+1]=t;}
cout<<"the sorted numbers are:";
for(i=0;i<10;i++)
cout<<setw(4)<<a[i];
cout<<endl;
return 0;
}
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int i;
- int f[40]={1,1};
- for(i=2;i<40;i++)
- f[i]=f[i-2]+f[i-1];
- for(i=0;i<40;i++)
- {
- if(i%4==0)
- cout<<endl;
- cout<<setw(12)<<f[i];
- }
- cout<<endl;
- return 0;
- }
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i;
int f[40]={1,1};
for(i=2;i<40;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<40;i++)
{
if(i%4==0)
cout<<endl;
cout<<setw(12)<<f[i];
}
cout<<endl;
return 0;
}
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int i;
- int j;
- int a[5][5];
- for (i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- if(i%2==0)
- a[i][j]=i*5+j+1;
- else
- [i][4-j]=i*5+j+1;
- }
- }
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- cout<<setw(4)<<a[i][j];
- cout<<endl;
- }
- return 0;
- }
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i;
int j;
int a[5][5];
for (i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i%2==0)
a[i][j]=i*5+j+1;
else
[i][4-j]=i*5+j+1;
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
cout<<setw(4)<<a[i][j];
cout<<endl;
}
return 0;
}
- #include<iostream>
- using namespace std;
- int main()
- {
- char str[50];
- cout<<"Please input strings:";
- cin.get(str,50);
- cout<<"The strings is:";
- cout<<str<<endl;
- return 0;
- }
#include<iostream>
using namespace std;
int main()
{
char str[50];
cout<<"Please input strings:";
cin.get(str,50);
cout<<"The strings is:";
cout<<str<<endl;
return 0;
}
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- int a[2][3];
- int i,j,big;
- cout<<"请输入二行三列二维数组的元素值:"<<endl;
- for(i=0;i<2;i++)
- for(j=0;j<3;j++)
- {
- cout<<"a["<<i<<"]"<<"["<<j<<"]=";
- cin>>a[i][j];
- }
- cout<<"该二维数组为:";
- for(i=0;i<2;i++)
- for(j=0;j<3;j++)
- {
- if(j%3==0)
- cout<<endl;
- cout<<setw(4)<<a[i][j];
- }
- cout<<endl;
- big=a[0][0];
- for(i=0;i<2;i++)
- for(j=0;j<3;j++)
- if(a[i][j]>=big)
- big=a[i][j];
- for(i=0;i<2;i++)
- for(j=0;j<3;j++)
- if(a[i][j]==big)
- cout<<"该数组中最大元素为:"<<"a["<<i<<"]"<<"["<<j<<"]="<<a[i][j];
- }
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a[2][3];
int i,j,big;
cout<<"请输入二行三列二维数组的元素值:"<<endl;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
cout<<"a["<<i<<"]"<<"["<<j<<"]=";
cin>>a[i][j];
}
cout<<"该二维数组为:";
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
if(j%3==0)
cout<<endl;
cout<<setw(4)<<a[i][j];
}
cout<<endl;
big=a[0][0];
for(i=0;i<2;i++)
for(j=0;j<3;j++)
if(a[i][j]>=big)
big=a[i][j];
for(i=0;i<2;i++)
for(j=0;j<3;j++)
if(a[i][j]==big)
cout<<"该数组中最大元素为:"<<"a["<<i<<"]"<<"["<<j<<"]="<<a[i][j];
}
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- char str[50];
- cout<<"Please input a string:";
- cin.get(str,50);
- cout<<"The length of string"<<str<<"is"<<strlen(str)<<endl;
- return 0;
- }
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
char str[50];
cout<<"Please input a string:";
cin.get(str,50);
cout<<"The length of string"<<str<<"is"<<strlen(str)<<endl;
return 0;
}
- #include<iostream>
- #include<cstring>
- using namespace std;
- int main()
- {
- char str[100];
- cout<<"请输入一个字符串:";
- cin.get(str,100);
- cout<<"字符串"<<str<<"的反向字符串为:";
- for(int i=strlen(str)-1;i>=0;i--)
- cout<<str[i];
- cout<<endl;
- return 0;
- }
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[100];
cout<<"请输入一个字符串:";
cin.get(str,100);
cout<<"字符串"<<str<<"的反向字符串为:";
for(int i=strlen(str)-1;i>=0;i--)
cout<<str[i];
cout<<endl;
return 0;
}
- #include <iostream>
- using namespace std;
- int main()
- {
- char s[]="This is C programming test.";
- int i=0,pLen=0,maxpLen = 0, pSeat = 0;
- while(s[i]!='\0')
- {
- while(s[i]!=' '&&s[i]!='\0')
- {
- pLen++;
- i++;
- }
- if(pLen>maxpLen)
- {
- pSeat=i-pLen;
- maxpLen=pLen;
- }
- while(s[i]==' ')
- i++;
- pLen=0;
- }
- cout <<"最长的单词 :";
- for(i=0;i<maxpLen;i++)
- cout << s[pSeat+i];
- cout <<endl;
- return 0;
- }
#include <iostream>
using namespace std;
int main()
{
char s[]="This is C programming test.";
int i=0,pLen=0,maxpLen = 0, pSeat = 0;
while(s[i]!='\0')
{
while(s[i]!=' '&&s[i]!='\0')
{
pLen++;
i++;
}
if(pLen>maxpLen)
{
pSeat=i-pLen;
maxpLen=pLen;
}
while(s[i]==' ')
i++;
pLen=0;
}
cout <<"最长的单词 :";
for(i=0;i<maxpLen;i++)
cout << s[pSeat+i];
cout <<endl;
return 0;
}
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- char str[50];
- cout<<"Please input a string:";
- cin.get(str,50);
- cout<<"The length of string"<<str<<"is"<<strlen(str)<<endl;
- return 0;
- }
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
char str[50];
cout<<"Please input a string:";
cin.get(str,50);
cout<<"The length of string"<<str<<"is"<<strlen(str)<<endl;
return 0;
}
- #include<iostream>
- #include<cstring>
- using namespace std;
- int main()
- {
- char str[10];
- cout<<"请输入字符串,直到输入 hello 后程序结束:"<<endl;
- do{
- cin>>str;
- }while(strcmp(str,"hello")!=0);
- return 0;
- }
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[10];
cout<<"请输入字符串,直到输入 hello 后程序结束:"<<endl;
do{
cin>>str;
}while(strcmp(str,"hello")!=0);
return 0;
}
- #include<iostream>
- using namespace std;
- int main()
- {
- char str[50];
- int len=0;
- cout<<"请输入一个字符串:";
- cin.get(str,50);
- while(str[len] !='\0')
- len++;
- cout<<"字符串"<<str<<"的长度"<<len<<endl;
- return 0;
- }
#include<iostream>
using namespace std;
int main()
{
char str[50];
int len=0;
cout<<"请输入一个字符串:";
cin.get(str,50);
while(str[len] !='\0')
len++;
cout<<"字符串"<<str<<"的长度"<<len<<endl;
return 0;
}