第一次编程作业,浅浅记录下

78c574d049324766ae98469941ae1c04.jpg

fa7afcd5e9924266bef2ca3b9013544f.jpg

36e5f061b09d431b8b03171b9804472b.jpg 

 

8ea0d8767cc1498c95ecb931d25b8f12.jpg

ae9dfa02e1aa4b11a10b8928d9463658.jpg 

 

 1.

(1)if编写

using namespace std;

int main (){

 char c;

 cin>>c;

 if(c>='A'&&c<='Z')

  

// cout<<c+32<<endl;

putchar(c+32);

if(c>='a'&&c<='z')

// cout<<c-32<<endl;

 putchar(c-32);

   if(c<65||c>(90&&c<97)||c>122) 

 putchar(c);

 return 0;

}

c865cc83d4b84e068331f1ad642f17a3.png

 

 (2)while编写

#include<iostream>

using namespace std;

int main (){

 char c;

 while(c=getchar()!='\n')

 {

 if(c>='A'&&c<='Z') 

    putchar(c+32);

    else if(c>='a'&&c<='z')

 putchar(c-32);

    else 

    putchar(c);

 }

}

 

 2.do-while和for编写

#include<iostream>

using namespace std;

int main (){

 char c;

  //do-while编写 

/* c=getchar();

 

 do

 {

 if(c>='A'&&c<='Z') 

    putchar(c+32);

    else if(c>='a'&&c<='z')

 putchar(c-32);

    else 

    putchar(c);

 

}

 while ((c=getchar())!='\n');

 */

 //for 编写

 for(;(c=getchar())!='\n';)

 {

   if(c>='A'&&c<='Z') 

    putchar(c+32);

    else if(c>='a'&&c<='z')

 putchar(c-32);

    else 

    putchar(c);

  } 

return 0;

}

5c1a371a3f0042ebb1beca1d574435a6.png

 3.

(1)

 #include<iostream>

using namespace std;

int main (){

float x,y;

cin>>x;

if(x<1)

y=x;

else if(x>=1&&x<10)

y=2*x-1;

else

y=3*x-11;

cout<<"y="<<y<<endl;

return 0;

}

751c18baeda74d16b6aacde3ed3b0f47.png

 (2)


#include<iostream>

using namespace std;

int main (){

int score;

cin>>score;

if(score>100)

cout<<"输入成绩无效,请重新输入!"; 

else if(score>=90&&score<=100)

cout<<"A";

else if(score>=80)

cout<<"B";

else if(score>=70)

cout<<"C";

else if(score>=60)

cout<<"D";

return 0;

}

992aae68a33a46f982626f061ec99030.png

 

 

 4.

#include<iostream>

using namespace std;

/*int main (){

int a,b,c,t;

cin>>a>>b>>c;

if(a>b)

t=a;

else t=b;

if(c>t)

cout<<c;

else

cout<<t;

return 0;

}

*/

//用max函数

 int max(int a,int b)

 {

  if(a>b)

       return a;

       else 

      return b; 

 }

int main(){

 int a,b,c,t;

 cin>>a>>b>>c;

 t=max(max(a,b),c);

 cout <<t;

}

269c6e6912e54e709ce0d94b44f50e99.png

 5.

#include<iostream>

using namespace std;

int main()

{

 int a,b,c,t;

 cin>>a>>b>>c;

 if(a<b){

  t=a;a=b;b=t;

 }

 if(a<c){

  t=a;a=c;c=t;

 }

 if(b<c){

  t=b;b=c;c=t;

 }

 cout<<a<<" "<<b<<" "<<c<<endl;

 return 0;

}

2eda0ec6e9114d41b27ab6f075493aed.png

 6.

#include<iostream>

using namespace std;

int main (){

/*int score;

cin>>score;

if(score>100)

cout<<"输入成绩无效,请重新输入!"; 

else if(score>=90&&score<=100)

cout<<"A";

else if(score>=80)

cout<<"B";

else if(score>=70)

cout<<"C";

else if(score>=60)

cout<<"D";*/

int score,k;

cin >>score;

k=score/10;

switch(k)

{

 case 10: 

 case 9: cout<<"A";

 break ;

 case 8: cout<<"B";

 break ;

 case 7: cout<<"C";

 break ;

 case 6: cout<<"D";

 break ;

 default:cout<<"E";

}

return 0;

}

4e70a5df8adb4bf6b7b239b77e9b4c78.png

 7.

#include<iostream>
using namespace std;
int main()
{
int a ,b,t;
cin>>a>>b;
t=a;
a=b;
b=t;
cout<<a<" "<b<<endl; 
    return 0;
}

4263e1dc744d4aefb9cfc23305bf2f08.png

8.

#include<iostream>

using namespace std;

int main ()

{

 int year;

 cin>>year;

 if((year%4==0&&year%100!=0)||(year%400==0))

 {

 cout<<year<<"是闰年"<<endl; 

 }else{

 cout<<year<<"不是闰年"<<endl; 

 }

}

ac96df35429e4eca985de509cd08ae44.png

9.

#include<iostream>
using namespace std;
int main()
{
    int year,n=0;
    year=1000;
while(year<=2020)
{
if((year%4==0&&year%100!=0||year%400==0))
    {
    
        cout<<year<<" "; n++;
            
        }
        year++; 
    }
        cout<<endl<<n;
        return 0;
}

409631dd10d8449eb32be73430a0ad5c.png

 10.

#include<iostream>
using namespace std;
int main()
{
int n,k;
cin>>n;
for(k=2;k<=n-1;k++)
if(n%k==0)
 break;
 if(k==n)
        cout<<"素数";
        else
        cout<<"非素数";
        return 0;
}

5c35e31d75184f6c85afdfb861e895f6.png

11.

#include<iostream>
using namespace std;
int main ()
{
int n,k;
for(n=1;n<=100;n++) 
{
    for(k=2;k<n;k++){
        if(n%k==0)
        {
            break;
        }
    }if(k==n){
        cout<<" "<<n;
    }
    }
cout<<endl;
}

672d3bb071004d2ab774b588ea501a64.png

 

12.

#include<iostream>

using namespace std;

int main()

{

int a,b,r,k;

cin>>a>>b;

k=a*b;

r=a%b;

while (r!=0)

{

 a=b;b=r;r=a%b;

}

cout<<"最大公约数是"<<b<<endl; 

cout<<"最大公倍数是"<<k/b<<endl;

return 0;

}

67d1c9fcfbaf4fc2afc7578652b9d091.png

 

13.

#include<iostream>
using namespace std;
int main()
{
int i,n,temp=1;
cin>>n;
for(i=1;i<=n;i++){
temp=temp*i;    
}
cout<<n<<"!="<<temp<<endl;
return 0;
}

070e6f6841f247e1a2d11a8688d7dc71.png

 14.

#include<iostream>
using namespace std;
int main()
{
int i,n,temp=1,sum=0;
cin>>n;
for(i=1;i<=n;i++){
temp=temp*i;
sum=sum+temp;    
}

cout<<n<<"!="<<temp<<endl;
cout<<"sum="<<sum<<endl;
return 0;
}

77bfb8304090464085d3a9a1ed8e67bd.png

 15.

#include<iostream>

using namespace std;

int main()

{

char c;

int alp=0,num=0,space=0,other=0;

while((c=getchar())!='\n')

{

 if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))

 alp++;

 else if(c>='0'&&c<='9')

 num++;

 else if(c==' ')

 space++;

 else

 other++;

}

cout<<alp<<" "<<num<<" "<<space<<" "<<other<<endl;

return 0;

}

5308a122c31a4efd96626de9bd400349.png

 16.

 //16

#include<iostream>

using namespace std;

int main()

{

 int i,n,sum=0 ;

 cin>>n;

 for(i=1;i<=2*n-1;i=i+2)

 { 

 sum=sum+i;

  cout<<sum;

  return 0;

}

2b2fbfae63d942709d68b7da1c117a8e.png

//16题拓展1-2+3-4··· 

int main()

{

 int i,n,sum=0,flag=1;

  cin>>n;

 for(i=1;i<=n;i=i+1)

 { 

 sum=sum+i*flag;

    flag=-flag;

 }

cout<<sum;

 return 0;

}

df62675d6cab4c42b594c8f59d90cf20.png

 17.
#include<iostream>
using namespace std;
int main()
{
    int n;
double flag=1;
double sum=0;
    cin>>n;
    for(double i=1;i<2*n-1;i=i+2)
{
sum=sum+1.0/i*flag;
    flag=-flag;
    }
    cout<<sum;
    return 0;    
}

ee3f34609e6f4b9ea34e12a3e58fb273.png

 18.

(1)

  //18.1
#include<iostream>
using namespace std;
int main()
{ int n,a,sum=0,i=1;
cin>>n>>a;

while(i<=n){
    sum=sum+a;
    a=a*10+2;
    i++;
}
cout <<sum;
return 0;
}

43f03152912c4fb6ab623214b3b1cb34.png

 (2)

  //18.2

#include<iostream>

using namespace std;

int main (){

int n ,i,sum;

for(n=2;n<=1000;n++)

{

sum=0;

 for(i=1;i<=n-1;i++)

 if(n%i==0)

 sum=sum+i;

 if(n==sum)

 {

  cout<<n<<", its factor are";

   for(i=1;i<=n-1;i++)

 if(n%i==0)

 cout<<i<<",";

 cout<<endl;

 }

}

return 0; 

}

e7f5e3ddc30b43f88ce3d8413c024677.png

 (3) 

//18.3

#include<iostream>

using namespace std;

int main ()

{ float a=2,b=1,sum=0,i=1,t;

for(i=1;i<=20;i++){

sum=sum+a/b;

t=b;

b=a;

a=a+t;

}

cout<<sum;

return 0;

}

dede56708fb8494d963a7672a9b00c38.png

 19.

  //19
#include<iostream>
using namespace std;
int main ()
{
 int n,k=0;
for(n=1;n<=1000;n++){
    if(n%3==2&&n%5==3&&n%7==2)
  {
    k++;
    if(k%5==0)
    {
    cout<<n<<" ";
    cout<<endl;
    }else
cout<<n<<" ";
}
}
return 0;

}

0c3a52f388214cb8ab293a3390a09c4d.png

//会的不多,加油学

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值