Discuz! Board

 找回密码
 立即注册
查看: 158|回复: 5

数组

[复制链接]

2

主题

8

帖子

36

积分

新手上路

Rank: 1

积分
36
发表于 2024-4-14 20:09:23 | 显示全部楼层 |阅读模式
#include<bits/stdc++.h>
int a=1,b=2;
int t;
void SWAP(){
        t=a;a=b;b=t
}
void test(int&a,&b){
        a=a+1,b=b+1;
}
int mai(){
        cout<<a<<''<<b<<endl;
        int a=10,b=20;
        SWAP();test(a,b);
        cout<<a<<''<<b;
}


回复

使用道具 举报

2

主题

8

帖子

36

积分

新手上路

Rank: 1

积分
36
 楼主| 发表于 2024-4-14 20:14:21 | 显示全部楼层
[C] 纯文本查看 复制代码
#include<bits/stdc++.h>
int a=1,b=2;
int t;
void SWAP(){
	t=a;a=b;b=t
} 
void test(int&a,&b){
	a=a+1,b=b+1;
}
int mai(){
	cout<<a<<' '<<b<<endl;
	int a=10,b=20;
	SWAP();test(a,b);
	cout<<a<<'  '<<b;
}[mw_shl_code=c,true]
[/mw_shl_code]
回复

使用道具 举报

2

主题

8

帖子

36

积分

新手上路

Rank: 1

积分
36
 楼主| 发表于 2024-4-14 20:21:36 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include<bits/stdc++.h>
int a=1,b=2;
int t;
void SWAP(){
	t=a;a=b;b=t
} 
void test(int&a,&b){
	a=a+1,b=b+1;
}
int main(){
	cout<<a<<' '<<b<<endl;
	int a=10,b=20;
	SWAP();test(a,b);
	cout<<a<<' '<<b;
}
回复

使用道具 举报

2

主题

8

帖子

36

积分

新手上路

Rank: 1

积分
36
 楼主| 发表于 2024-4-20 18:36:02 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main() {
	int m;
	int n;
	int sum=0;
	scanf("%d %d",m,n);
	for(int i=m;i<=n;i++)
	{
		if(i%2==1)//i=i+2;
	
	sum=sum+i;
    }
	printf("%d",sum);
	

    
    return 0;
}
回复

使用道具 举报

2

主题

8

帖子

36

积分

新手上路

Rank: 1

积分
36
 楼主| 发表于 2024-5-2 22:40:59 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main() {
	int m;
	scanf("%d",&m);
	printf("%d",m);
	if(m<=0||m>11){
		printf("输入错误:\n");
		return 1; 
	}
double sum=0.0;
int n=1;
while(sum<m){
	sum+=1.0/n;
	n++;
    }
    printf("满足不等式最小的n值为:/n");
    printf("n=%d");
 return 0;
}
回复

使用道具 举报

574

主题

758

帖子

243万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2435189

烈空座 Lv:100
发表于 2024-5-2 22:51:55 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int main() {
    int m;
    scanf("%d",&m);
    printf("%d",m);//不需要输出m值 
    if(m<=0||m>11){
        printf("输入错误:\n");
        return 1; 
    }
        double sum=0.0;
        int n=1;
        while(sum<m)
        {
            sum+=1.0/n;
            n++;//注意这里,当找到满足sum>=m的n时,n还是会在这里+1,所以输出结果是n-1 
    }
    printf("满足不等式最小的n值为:/n");//转义符为\,'\n'回车。这里的输出可以不要,题目未做要求,包括下面的n=
    printf("n=%d");//printf("n=%d",n-1);
         return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 05:13 , Processed in 0.053358 second(s), 28 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表