Get the App
SLTechnology News&Howtos  ›  Development  › 

How to encapsulate function digit string in C language

Shulou Source: shulou.com Published: 2022-06-01 04:29:26 09月10日 Update

This article mainly explains "how C language encapsulates letter digital strings". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "how C language encapsulates function digital strings".

Encapsulated function: judging leap years and peaceful years

This function determines whether the incoming year is a leap year and a peaceful year, and the result is represented by the return value.

# include / / function declaration int GetYearSate (int year); int main () {int year; printf ("Please enter year:"); scanf ("% d", & year); / / judging leap year and year if (GetYearSate (year)) {printf ("normal year.\ n");} else {printf ("Leap year.\ n");} return 0 Function function: judge the return value of leap year in normal year: 0 indicates leap year 1 indicates normal year * / int GetYearSate (int year) {if ((year%4==0 & & year0 years 0) | | (year%400==0)) {return 0;} return 1;} encapsulates function: string lookup (see strstr)

The first step is to see help: man strstr

# include # include / / declare the function's char * my_strstr (char * src_str,char * find_str); int main () {char src_str [100]; / / "123456789" char find_str [100]; printf ("Please enter string:"); scanf ("% s", src_str); printf ("Please enter the string you are looking for:"); scanf ("% s", find_str) / / strstr () / / finds the specified string and returns the first address of the lookup string in the source string printf ("found string result:% s\ n", strstr (src_str,find_str)); printf ("found string result:% s\ n", my_strstr (src_str,find_str)); return 0 } / / function function: string lookup function / / return value: return the found string address char * my_strstr (char * src_str,char * find_str) {int src_len; int find_len; int iJournal j; src_len=strlen (src_str); find_len=strlen (find_str); for (iS0) ISome0' & * str='0' & & * strcnt_f) {cnt=cnt_f;} data_f+=data*my_pow (0.1Magneto cnt); return data_f;} / / function function: calculate the y power of x / / my_pow (2mai 3); double my_pow (double x pencil int y) {double tmp=1.0; int i; for (iMago match I)

Tags: Characters strings functions input encapsulation functions integers data results uppercase lowercase points commas palindromes normal years leap years addresses letters parts references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno NVidia Shulou Technology vpn