首页 > 编程语言 >C++第二天

C++第二天

时间:2023-04-11 20:23:53浏览次数:50  
标签:return cout area int sum cin C++ 第二天

计算正五边形的周长和面积

#include <bits/stdc++.h>
using namespace std;
int main()
{
    double n,S,C;
    double a,b;
    cin>>n;
    a=sqrt(5);
    b=25+10*a;
    S=sqrt(b)/4*n*n;
    cout<<S<<endl;
    C=5*n;
    cout<<C<<endl;
    return 0;
}

 

计算长方形面积和表面积

#include<iostream>
#include<string>
using namespace std;
int area(int x,int y)
{
    int a;
    a=x*y;
    return a;
}
int area(int x,int y,int z)
{
    int m,n,h,sum;
    m=x*y;
    n=x*z;
    h=y*z;
    sum=(m+n+h)*2;
    return sum;
}
int main()
{
    int i, repeat, c, x, y, z;
    cin>>repeat;
    for(i=0;i<repeat;i++){
        cin>>c;
        if(c==2){
            cin>>x>>y;
            cout<<area(x,y)<<endl;
        }
        if(c==3){
            cin>>x>>y>>z;
            cout<<area(x,y,z)<<endl;
        }
    }
    return 0;
}

标签:return,cout,area,int,sum,cin,C++,第二天
From: https://www.cnblogs.com/zh-ang-zhang/p/17307528.html

相关文章

  • C++创建线程
    C++11中使用std::thread来创建线程。一、创建线程#include<iostream>#include<thread>#include<mutex>/*函数指针创建线程*/voidthread_func(intsize){std::cout<<"thread_func:"<<std::this_thread::get_id()<<std::en......
  • C++第二章课后练习题 2-24,2-25
    编写一个完整的程序,实现功能:向用户提问“现在正在下雨吗?”,提示用户输入Y或N。若输入为Y,显示“现在正在下雨。”;若输入为N,显示“现在没有下雨。”;否则继续提问“现在正在下雨吗?”。#include<iostream>usingnamespacestd;intmain(){cout<<"现在正在下雨吗?"<<endl;......
  • 标 题: 让 Python 拥有 C/C++ 一样的速度,编译神器 Codon 发布!
    发信人:mseer(mseer),信区:Python标题:让Python拥有C/C++一样的速度,编译神器Codon发布!发信站:水木社区(TueMar1423:52:022023),站内https://mp.weixin.qq.com/s/n5LRxftQiiP8FO6nvyL3-g为了解决这一难题,麻省理工学院的计算机科学家出手了,他们共同研发了一......
  • C++核心编程之-函数提高
    函数提高函数默认参数在c++中,函数的形参列表中的形参是可以有默认值的。语法:返回值类型函数名(参数=默认值){}注意点:1、如果某个位置参数有默认值,那么从这个位置往后,必须都要有默认值​ 2、如果函数声明有默认值,函数实现的时候就不能有默认参数函数占位参数C++中......
  • 转:C#与C++数据类型转换
    (94条消息)C#与C++数据类型转换_c#c++类型转换_终有期_的博客-CSDN博客c++:HANDLE(void*)----c#:System.IntPtrc++:Byte(unsignedchar)----c#:System.Bytec++:SHORT(short)----c#:System.Int16c++:WORD(unsignedshort)----c#......
  • C++核心编程之-引用
    引用引用的基本使用作用:给变量起别名语法:数据类型&别名=原名引用的注意事项引用必须初始化引用在初始化后,不可以改变示例:#include<iostream>usingnamespacestd;intmain(){ inta=30; intb=50; //int&c;//这行错误,引用必须初始化 int&c=a......
  • Code-C++-fstream-输出到文件(待完善)
    Code-C++-fstream-输出到文件#include<fstream>#include<string>voidexportFile(std::stringstrFileName,intnVal){std::stringstrFilePath="./"+strFileName;std::ofstreamosFile(strFilePath.c_str(),std::ios::app|std......
  • 高精度加法C++
    #include<iostream>#include<vector>usingnamespacestd;vector<int>Add(vector<int>&A,vector<int>&B){vector<int>C;intt=0;for(inti=0;i<A.size()||i<B.size();i++){if(i<A.size(......
  • C++-C11-chrono-获取当前时间、获取阶段时间
    C++-C11-chrono-获取当前时间、获取阶段时间Linux下使用C++11的chrono库获取时间。#include<chrono>#include<thread>#include<iostream>int64_tgetCurrentLocalTimeStamp(){std::chrono::time_point<std::chrono::system_clock,std::chrono::millisec......
  • C++第一天
    简单的C++程序实例#include<iostream>usingnamespacestd;intmain(){  cout<<"hello!"<<endl;  cout<<"welcomtoC++!"<<endl;  return0;}输出:Hello!welcometoC++!......