亚洲一级免费看,特黄特色大片免费观看播放器,777毛片,久久久久国产一区二区三区四区,欧美三级一区二区,国产精品一区二区久久久久,人人澡人人草

C語(yǔ)言

C語(yǔ)言基礎(chǔ)知識(shí)

時(shí)間:2025-03-28 22:50:50 C語(yǔ)言 我要投稿

C語(yǔ)言基礎(chǔ)知識(shí)集錦

  懂編程語(yǔ)言,有寫(xiě)一些項(xiàng)目的經(jīng)驗(yàn),能夠看懂一些比較復(fù)雜項(xiàng)目的代碼對(duì)我們是十分有幫助的,下面小編為大家整理了一些C語(yǔ)言基礎(chǔ)知識(shí),一起來(lái)看看吧: 

C語(yǔ)言基礎(chǔ)知識(shí)集錦

  1、C語(yǔ)言檢查是元音還是輔音

  #include

  int main(){

  char c;

  printf("Enter an alphabet: ");

  scanf("%c",&c);

  if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U')

  printf("%c is a vowel.",c);

  else

  printf("%c is a consonant.",c);

  return 0;

  }

  輸出1:

  Enter an alphabet: i

  i is a vowel.

  輸出2:

  Enter an alphabet: G

  G is a consonant.

  也可以用條件運(yùn)算符解決

  /* C program to check whether a character is vowel or consonant using conditional operator */

  #include

  int main(){

  char c;

  printf("Enter an alphabet: ");

  scanf("%c",&c);

  (c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U') ? printf("%c is a vowel.",c) : printf("%c is a consonant.",c);

  return 0;

  }

  輸出結(jié)果和上面的程序相同。

  2、C語(yǔ)言實(shí)現(xiàn)從三個(gè)數(shù)值中查找最大值

  實(shí)現(xiàn)1:

  /* C program to find largest number using if statement only */

  #include

  int main(){

  float a, b, c;

  printf("Enter three numbers: ");

  scanf("%f %f %f", &a, &b, &c);

  if(a>=b && a>=c)

  printf("Largest number = %.2f", a);

  if(b>=a && b>=c)

  printf("Largest number = %.2f", b);

  if(c>=a && c>=b)

  printf("Largest number = %.2f", c);

  return 0;

  }

  實(shí)現(xiàn)2:

  /* C program to find largest number using if...else statement */

  #include

  int main(){

  float a, b, c;

  printf("Enter three numbers: ");

  scanf("%f %f %f", &a, &b, &c);

  if (a>=b)

  {

  if(a>=c)

  printf("Largest number = %.2f",a);

  else

  printf("Largest number = %.2f",c);

  }

  else

  {

  if(b>=c)

  printf("Largest number = %.2f",b);

  else

  printf("Largest number = %.2f",c);

  }

  return 0;

  }

  實(shí)現(xiàn)3:

  /* C Program to find largest number using nested if...else statement */

  #include

  int main(){

  float a, b, c;

  printf("Enter three numbers: ");

  scanf("%f %f %f", &a, &b, &c);

  if(a>=b && a>=c)

  printf("Largest number = %.2f", a);

  else if(b>=a && b>=c)

  printf("Largest number = %.2f", b);

  else

  printf("Largest number = %.2f", c);

  return 0;

  }

  輸出結(jié)果相同:

  Enter three numbers: 12.2

  13.452

  10.193

  Largest number = 13.45

  3、C語(yǔ)言解一元二次方程

  /* Program to find roots of a quadratic equation when coefficients are entered by user. */

  /* Library function sqrt() computes the square root. */

  #include

  #include /* This is needed to use sqrt() function.*/

  int main()

  {

  float a, b, c, determinant, r1,r2, real, imag;

  printf("Enter coefficients a, b and c: ");

  scanf("%f%f%f",&a,&b,&c);

  determinant=b*b-4*a*c;

  if (determinant>0)

  {

  r1= (-b+sqrt(determinant))/(2*a);

  r2= (-b-sqrt(determinant))/(2*a);

  printf("Roots are: %.2f and %.2f",r1 , r2);

  }

  else if (determinant==0)

  {

  r1 = r2 = -b/(2*a);

  printf("Roots are: %.2f and %.2f", r1, r2);

  }

  else

  {

  real= -b/(2*a);

  imag = sqrt(-determinant)/(2*a);

  printf("Roots are: %.2f+%.2fi and %.2f-%.2fi", real, imag, real, imag);

  }

  return 0;

  輸出1:

  Enter coefficients a, b and c: 2.3

  4

  5.6

  Roots are: -0.87+1.30i and -0.87-1.30i

  輸出2:

  Enter coefficients a, b and c: 4

  1

  0

  Roots are: 0.00 and -0.25

  4、C語(yǔ)言檢查是否是閏年

  /* C program to check whether a year is leap year or not using if else statement.*/

  #include

  int main(){

  int year;

  printf("Enter a year: ");

  scanf("%d",&year);

  if(year%4 == 0)

  {

  if( year%100 == 0) /* Checking for a century year */

  {

  if ( year%400 == 0)

  printf("%d is a leap year.", year);

  else

  printf("%d is not a leap year.", year);

  }

  else

  printf("%d is a leap year.", year );

  }

  else

  printf("%d is not a leap year.", year);

  return 0;

  }

  輸出1:

  Enter year: 2000

  2000 is a leap year.

  輸出2:

  Enter year: 1900

  1900 is not a leap year.

  輸出3:

  Enter year: 2012

  2012 is a leap year.


【C語(yǔ)言基礎(chǔ)知識(shí)】相關(guān)文章:

C語(yǔ)言基礎(chǔ)知識(shí)02-19

C語(yǔ)言的基礎(chǔ)知識(shí)08-16

c語(yǔ)言入門(mén)基礎(chǔ)知識(shí)07-18

C語(yǔ)言程序基礎(chǔ)知識(shí)05-19

C語(yǔ)言基礎(chǔ)知識(shí)總結(jié)04-15

C語(yǔ)言基礎(chǔ)知識(shí)大全02-02

c語(yǔ)言公共基礎(chǔ)知識(shí)06-21

C語(yǔ)言基礎(chǔ)知識(shí)匯總07-15

C語(yǔ)言位運(yùn)算的基礎(chǔ)知識(shí)05-27