当前位置:网站首页>(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
2022-07-02 12:06:00 【Study silently every day】
We know , A program contains a small algorithm , Program is the implementation of Algorithm .
So in real life , We can use some code to implement some calculations , In terms of the ability of our primary procedural apes , We can implement small algorithms through programs , such as 1+2+3+······+100, We all know Gauss Algorithm ,(1+100)*50=5050, Now we can realize it by program , As shown below :
#include<stdio.h>
int main()
{
int i,n=0;
for(i=0;i<=100;i++)
{
n+=i;
}
printf("1+2+3+···+100=%d",n);
} The following is the operation interface :

We can contact from junior high school C Programming , When others are still taking calculators , We have started to write our own computing programs in code , Isn't it very COOL, With the development of technology , We have more and more learning channels , Such as network , We can take courses from the best universities in the world , Through video teaching , We can listen to the lessons we want at home , Learn what we want to learn .
therefore , Now is a world of self-study , Find your own learning content , Improve yourself , meanwhile , We can appropriately improve our hands-on ability , For example, make some small furniture , Or write code , Or learn SCM , Or learn some skills , however , Now China is also developing , Improve the quality and diversity of Education , For example, primary school students have a lot of housework and other classes , All very good , We don't just read , Recite , Problem. , We also need to do real things .
And today's topic is 2 The first code is to judge the average year , Leap year , We all know , A year , If it can be 4 to be divisible by , At the same time, it cannot be 100 to be divisible by , So this year is leap year , If a year can be 400 to be divisible by , So this year is leap year , The rest of the years are normal , So how do we implement this algorithm ?
#include<stdio.h> // The header file
int main() // Main function entry
{
int year; // Define an integer variable year
printf(" Please enter a year :"); // Print out : Please enter a year
scanf("%d",&year); // Enter a year , such as 2030
if((year%400 == 0)||(year%4==0&&year%100 !=0)) // Judge , Whether this year can be 400 to be divisible by , Or the concept can be 4 Divisible at the same time cannot be 100 to be divisible by
printf(" Leap year "); // If meet if Conditions , Print : Leap year
else
printf(" Ordinary year "); // If not satisfied if Conditions , Print : Ordinary year
return 0; // return 0
}The code has been explained clearly through comments , I can't describe more here , This code is also a very simple code , By reading the code , Then change the code , I'll write the code myself when I have time , You can learn to write code slowly . Everyone said C Is the most basic language , If you learn C Language , Then you can learn other programming languages , meanwhile , There are specialized skills , At most, we are proficient in 1-2 Languages , Train yourself for a long time , Can become more and more powerful , Other languages , We can understand it , After all, our time and energy are limited .
The following is the operation interface : 
OK, The above is the learning of this simple code , We are all training , Train your ability , When you have time, open the computer and type a code , Slowly , Will become more and more skilled , In the future, I can engage in software development .
Now let's share the first 3 Code :
#include <stdio.h>
// Definition pi by 3.14
#define pi 3.14
// Statement findCircumference() function
double findCircumference(double r);
double findArea(double r);
int main() {
double c; // Define the circumference of the circle
double r; // Define the radius of the circle
double s;
// Of course, it can also be written in the following form
//float c,r;
printf("Please input the radius:"); // Give a prompt for what you need to enter
scanf("%lf",&r); // Read the entered radius length from the keyboard
c=findCircumference(r);
s=findArea(r); // call findCircumference() function , Pass the value of radius into this function , Calculate the circumference of a circle , And assign the result to the variable c
printf("The circumference is: %.2lf\n",c); // Print the circumference of the circle on the screen
printf("The area is:%.2lf",s);
return 0; // End procedure
}
/**
* This function is used to calculate the circumference of a circle
* The parameter passed in is the radius of the circle
* The returned parameter is the length of the circle
*/
double findCircumference(double r){
double c; // Define the circumference of the circle , local variable , Only valid in this function
c=2*pi*r; // Calculate the circumference of a circle
return c; // Return the circumference of the circle
}
double findArea(double r){
double s; // Define the area of the circle , local variable , Only valid in this function
s=pi*r*r; // Calculate the area of a circle
return s; // Returns the area of the circle
}Or that sentence , There are specialized skills , Our time and energy are limited , We need a long time of immersive programming , Some students may like programming very much , Some students don't like it very much , therefore , It still depends on personal interests , therefore , Find your own interests , Just study for decades , Take it as a skill of your own , You can even make your skills feel artistic .
OK, Thank you for your browsing , thank you all . I will continue to learn C Language , There is embedded software development , Try to make some interesting embedded systems to share with you , I am also constantly learning , meanwhile , I will insist on writing blog, Strive for better and better content , At the same time, writing skills continue to improve , Improve the excellence of the content and the readability of the document , Try to bring you different feelings .
边栏推荐
- (C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
- BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
- Develop scalable contracts based on hardhat and openzeppelin (I)
- 自然语言处理系列(二)——使用RNN搭建字符级语言模型
- Uniapp uni list item @click, uniapp uni list item jump with parameters
- The position of the first underline selected by the vant tabs component is abnormal
- Leetcode14 最长公共前缀
- 行業的分析
- SVO2系列之深度濾波DepthFilter
- 二分刷题记录(洛谷题单)区间的甄别
猜你喜欢

Mish shake the new successor of the deep learning relu activation function

HOW TO ADD P-VALUES TO GGPLOT FACETS

自然语言处理系列(三)——LSTM

ES集群中节点与分片的区别

多文件程序X32dbg动态调试

Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer

mysql索引和事务

ESP32 Arduino 引入LVGL 碰到的一些问题

数据分析 - matplotlib示例代码

How to Create a Beautiful Plots in R with Summary Statistics Labels
随机推荐
SSH automatically disconnects (pretends to be dead) after a period of no operation
Take you ten days to easily finish the finale of go micro services (distributed transactions)
qt 仪表自定义控件
通讯录的实现(文件版本)
全链路压测
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)
动态内存(进阶四)
Leetcode922 sort array by parity II
二分刷题记录(洛谷题单)区间的甄别
Research on and off the Oracle chain
conda常用命令汇总
post请求体内容无法重复获取
【C语言】十进制数转换成二进制数
lombok常用注解
Industry analysis
5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
YYGH-BUG-05
Dynamic debugging of multi file program x32dbg
Leetcode topic [array] -540- single element in an ordered array