奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

C語言

C語言基礎(chǔ)常識

時間:2024-10-28 11:10:33 C語言 我要投稿
  • 相關(guān)推薦

C語言基礎(chǔ)常識

  相對初級的算法,適合剛開始學C語言的同學。下面這些C語言基礎(chǔ)常識都是經(jīng)過測試和驗證過了的,歡迎各位使用。

  1、C語言打印一條語句

  源代碼:

  /* C Program to print a sentence. */

  #include <stdio.h>

  int main()

  {

  printf("C Programming"); /* printf() prints the content inside quotation */

  return 0;

  }

  輸出:

  C Programming

  2、C語言打印用戶輸入的一個整數(shù)

  #include <stdio.h>

  int main()

  {

  int num;

  printf("Enter a integer: ");

  scanf("%d",&num);  /* Storing a integer entered by user in variable num */

  printf("You entered: %d",num);

  return 0;

  }

  輸出:

  Enter a integer: 25

  You entered: 25

  3、C語言實現(xiàn)兩個整數(shù)相加

  /*C programming source code to add and display the sum of two integers entered by user */

  #include <stdio.h>

  int main( )

  {

  int num1, num2, sum;

  printf("Enter two integers: ");

  scanf("%d %d",&num1,&num2); /* Stores the two integer entered by user in variable num1 and num2 */

  sum=num1+num2;      /* Performs addition and stores it in variable sum */

  printf("Sum: %d",sum);  /* Displays sum */

  return 0;

  }

  輸出:

  Enter two integers: 12

  11

  Sum: 23

  4、C語言實現(xiàn)兩個小數(shù)相乘

  /*C program to multiply and display the product of two floating point numbers entered by user. */

  #include <stdio.h>

  int main( )

  {

  float num1, num2, product;

  printf("Enter two numbers: ");

  scanf("%f %f",&num1,&num2);        /* Stores the two floating point numbers entered by user in variable num1 and num2 respectively */

  product = num1*num2;  /* Performs multiplication and stores it */

  printf("Product: %f",product);

  return 0;

  }

  輸出:

  Enter two numbers: 2.4

  1.1

  Product: 2.640000

  5、C語言查找字符的ASCII值

  /* Source code to find ASCII value of a character entered by user */

  #include <stdio.h>

  int main(){

  char c;

  printf("Enter a character: ");

  scanf("%c",&c);        /* Takes a character from user */

  printf("ASCII value of %c = %d",c,c);

  return 0;

  }

  輸出:

  Enter a character: G

  ASCII value of G = 71

  6、C語言根據(jù)用戶輸入的整數(shù)做商和余數(shù)

  /* C Program to compute remainder and quotient  */

  #include <stdio.h>

  int main(){

  int dividend, divisor, quotient, remainder;

  printf("Enter dividend: ");

  scanf("%d",&dividend);

  printf("Enter divisor: ");

  scanf("%d",&divisor);

  quotient=dividend/divisor;           /*  Computes quotient */

  remainder=dividend%divisor;          /* Computes remainder */

  printf("Quotient = %d ",quotient);

  printf("Remainder = %d",remainder);

  return 0;

  }

  輸出:

  Enter dividend: 25

  Enter divisor: 4

  Quotient = 6

  Remainder = 1

  7、C語言獲取整型、單精度浮點型、雙精度浮點型和字符型的長度

  基本語法:

  /* This program computes the size of variable using sizeof operator.*/

  #include <stdio.h>

  int main(){

  int a;

  float b;

  double c;

  char d;

  printf("Size of int: %d bytes ",sizeof(a));

  printf("Size of float: %d bytes ",sizeof(b));

  printf("Size of double: %d bytes ",sizeof(c));

  printf("Size of char: %d byte ",sizeof(d));

  return 0;

  }

  輸出:

  Size of int: 4 bytes

  Size of float: 4 bytes

  Size of double: 8 bytes

  Size of char: 1 byte

  8、C語言獲取關(guān)鍵字long的長度范圍

  #include <stdio.h>

  int main(){

  int a;

  long int b;                /* int is optional. */

  long long int c;            /* int is optional. */

  printf("Size of int = %d bytes ",sizeof(a));

  printf("Size of long int = %ld bytes ",sizeof(b));

  printf("Size of long long int = %ld bytes",sizeof(c));

  return 0;

  }

  輸出:

  Size of int = 4 bytes

  Size of long int = 4 bytes

  Size of long long int = 8 bytes

  9、C語言交換數(shù)值

  #include <stdio.h>

  int main(){

  float a, b, temp;

  printf("Enter value of a: ");

  scanf("%f",&a);

  printf("Enter value of b: ");

  scanf("%f",&b);

  temp = a;    /* Value of a is stored in variable temp */

  a = b;       /* Value of b is stored in variable a */

  b = temp;    /* Value of temp(which contains initial value of a) is stored in variable b*/

  printf(" After swapping, value of a = %.2f ", a);

  printf("After swapping, value of b = %.2f", b);

  return 0;

  }

  輸出:

  Enter value of a: 1.20

  Enter value of b: 2.45

  After swapping, value of a = 2.45

  After swapping, value of b = 1.2

  10、C語言檢查數(shù)值是奇數(shù)還是偶數(shù)

  /*C program to check whether a number entered by user is even or odd. */

  #include <stdio.h>

  int main(){

  int num;

  printf("Enter an integer you want to check: ");

  scanf("%d",&num);

  if((num%2)==0)      /* Checking whether remainder is 0 or not. */

  printf("%d is even.",num);

  else

  printf("%d is odd.",num);

  return 0;

  }

  輸出1:

  Enter an integer you want to check: 25

  25 is odd.

  輸出2:

  Enter an integer you want to check: 12

  12 is even.

  也可以用條件運算符解決:

  /* C program to check whether an integer is odd or even using conditional operator */

  #include <stdio.h>

  int main(){

  int num;

  printf("Enter an integer you want to check: ");

  scanf("%d",&num);

  ((num%2)==0) ? printf("%d is even.",num) : printf("%d is odd.",num);

  return 0;

  }

  11、C語言檢查是元音還是輔音

  #include <stdio.h>

  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.

  也可以用條件運算符解決

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

  #include <stdio.h>

  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é)果和上面的程序相同。

  12、C語言實現(xiàn)從三個數(shù)值中查找最大值

  實現(xiàn)1:

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

  #include <stdio.h>

  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;

  }

  實現(xiàn)2:

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

  #include <stdio.h>

  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;

  }

  實現(xiàn)3:

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

  #include <stdio.h>

  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

  13、C語言解一元二次方程

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

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

  #include <stdio.h>

  #include <math.h> /* 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

  14、C語言檢查是否是閏年

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

  #include <stdio.h>

  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語言基礎(chǔ)常識】相關(guān)文章:

C語言的基礎(chǔ)練習09-02

C語言編程基礎(chǔ)08-17

c語言基礎(chǔ)習題10-13

C 語言基礎(chǔ)教程07-22

C語言基礎(chǔ)循環(huán)結(jié)構(gòu)07-28

C語言基礎(chǔ)知識10-13

c語言入門基礎(chǔ)知識07-18

C語言基礎(chǔ)知識總結(jié)09-13

C語言基礎(chǔ)之編碼規(guī)范07-15

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

主站蜘蛛池模板: 南平市| 潜山县| 扎赉特旗| 黔南| 邯郸县| 汾西县| 三穗县| 师宗县| 舒兰市| 翁牛特旗| 汝阳县| 灵武市| 盐池县| 尚志市| 枞阳县| 出国| 曲阜市| 北京市| 平定县| 张家口市| 天台县| 南平市| 岫岩| 连州市| 晋州市| 桑日县| 武陟县| 和林格尔县| 微博| 勐海县| 仪征市| 宝坻区| 都安| 江安县| 安顺市| 阳新县| 上林县| 杭州市| 曲麻莱县| 固镇县| 乌鲁木齐市|