简单的c语言

  • #include <stdio.h>

main ()

{

tips();       /*caller*/

printf(“\n Success is about banging on after others have let go”);

}

tips()               /*caller*/

{

printf (“\n When you reach the end of the rope tie a knot & hang on”,)0;

}



[上述程序的输出结果如下:

When you reach the end of the ropt tie a knot & hang on.

Success is about hanging on after others have let go.]



  • #include <stdio.h>

main()

{

int a,fact;

printf(“\nEnter any number”);

scanf(“%d”,&a);

fact=rec(a);

printf(“Factorial value is%d”,fact);

}

rec(x);

int x;

{

int f;

if(x==1)

return(1);

else

f=x*rec(x-1);

return(f);

}


[其显示的结果为:  Factorial value is 2.]



  • 比较两个数较大的那个:

#include <stdio.h>

main()

{

int a,b,max;

scanf (“%d%d”,&a,&b);

if (a>b)

max=a;

else max=b;

printf (“%d”,max);

}




  • 输出a+b的值:

#include <stdio.h>

void main()

{

int a,b,x;

scanf (“%d%d”,&a,&b);

x=a+b;

printf (“%d”,x);

}



  • 输出a,b中最大的一位数:

#include <stdio.h>

int max(int x,int y)

{

int z;

if (x>y) z=x;

else z=y;

return(z);

}

void main()

{

int a,b,c;

scanf (“%d%d”,&a,&b);

c=max(a,b);

printf (“%d\n”,c);

}


  • 输出Hello:

#include <stdio.h>

int main()

{

printf (“Hello!”);

return 0;

}


  • 1~100的和:

#include <stdio.h>

int main()

{

int s,n;

s=0,n=1;

A: s=s+n;

n=n+1;

if (n<=100)

goto A;

printf (“%d”,s);}



  • 请输入一个三位数,将其各位逆序输出:(如153,输出351

#include <stdio.h>

void main()

{

int x,y,a,b,c;

printf ("请输入一个三位数的数:");

scanf("%d",&x);

a=x/100;

b=x%100/10;

c=x%10;

y=c*100+b*10+a;

printf ("\n%d",y);

}

#include <stdio.h>

void main()

{

int x,a,b,c,d;

printf ("请输入一个三位数的数:");

scanf("%d",&x);

a=x/100;

b=x%100/10;

c=x%10;

d=c*100+b*10+a;

printf ("\n%d\n",d);


}


买鸡:

#include <stdio.h>

void main()

{

int x,y,z;

if(x>=0&&x<=19,y>=0&&y<=33,z>=0&&z<=100)

while (x=19)

{

x=0;

    5*x+3*y+z/3==100&&x+y+z==100;

x=x+1;

}

printf("%d%d%d",x,y,z);

}



y==(100-5*x-z/3)/3&&y==100-x-z;

z==(100-5*x-3*y)*3&&z==100-x-y;



#include <stdio.h>

void main()

{

int x=0,y,z;

while (x<=19)

{

5*x+3*y+z/3==100&&x+y+z==100;

x=x+1;

printf("%d%d%d",x,y,z);

}

}





#include <stdio.h>

void main()

{

int x=0,y=0,z=0;

while (x<=19)

{

while (y<=33)

{

while (z<=100)

{

z==(100-5*x-3*y)*3&&z==100-x-y;

z=z+1;

printf("%d\t",z);

}

y==(100-5*x-z/3)/3&&y==100-x-z;

y=y+1;

printf("%d\t",y);

}

x=x+1;

printf("%d\t",x);

}

}


  • 计算x=20+3(x-1):

#include <stdio.h>

void main()

{

int age(int x)

int i,j;

scanf(“%d”,&i);

j=age(i);

printf(“age=%d\n”,j);

}

int age(int x)

{int z;

if(x==1) z=20;

else z=age(x-1)+3;

return(z);

}


  • 编写程序求圆柱体的表面积和体积:

#include <stdio.h>

#define PI 3.14       /*定义PI为符号常量,值为3.14*/

void main()

{

float r,h,s,v;

printf(“请输入半径r和高h的值:\n”);

scanf(“%f%f”,&r,&h);     /*输入半径r和高h*/

s=2*PI*r*h;               /*计算圆柱体表面积*/

v=PI*r*r*h;              /*计算圆柱体体积*/

printf(“s=%f,v=%f\n”,s,v);

}


  • 自增,自减运算符的使用:

#include <stdio.h>

void main()

{

int i=5,j=5;

int x,y;

x=i++;

y=++j;

printf(“%d\t%d\n”,-x++,-(++y));

printf(“%d\t%d\t%d\t%d\n”,i,j,x,y);

}


  • 自增、自减运算符的基本运算:

#include <stdio.h>

void main()

{

int k=4;

int x,y,z;

x=18-k++;

printf(“x=%d”,x);

printf(“k=%d\n”,k);

y=++k+6;

printf(“y=%d”,y);

printf(“k=%d\n”,k);

z=++k+k++;

printf(“z=%d\n”,z);

}

结果:x=14,k=5;y=12,k=6;z=14.



  • 输出单个字符:

#include <stdio.h>

void main()

{

char a,b;

a=’o’;

b=’k’;

putchar(a);

putchar(b);

putchar(‘\n’);

}



  • 输入字符举例:

#include <stdio.h>

void main()

{

char c;

c=getchar();       /*从键盘读入一个字符*/

putchar(c); /*显示输入的字符*/

}


猜数游戏:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main()

{

int x,i=0,guess;

srand(time(NULL));

x=rand()%100+1;

printf("请你猜数:");

do

{

scanf("%d",&guess);

if(x<guess)

{

printf ("你猜大了!\n");

}

else 

{

if(x>guess)

printf("你猜小了!\n");

else

{

printf("你赢了!\n");

break;

}

}

i++;

if (i>=10)

{

printf("随机数是:%d\n",x);

printf("你已经猜 错了10次,我赢了,哈哈!\n");

break;

}

printf("请你再猜:"); 

}while(1);

}


#include <stdio.h>

void main()

{

int a=2,*p=&a,*q=&a;

Printf("%d,%d\n",*p++,*(q++));

P=&a;q=&;

Printf ("%d%d\n",*p,(*q)++);

Printf("%d%d\n",*p,++(*q);

}

结果为:2,2

        2,2

        4,4

(从又向左算)







#include <stdio,h>

Void main()

{

Int a,b,c;

Int *pa,*pb,*pc;

Pa=&a;pb=&b;pc=&c;

Scanf ("%d%d",pa,pb);

Printf ("a=%d,b=%d\n",*pa,*pb);

C=a+b;

Printf ("c=%d\n",*pc);

*pc=a+*pb;

Printf ("c=%d
















100200之间有哪些数除42,除73,除95

#include<stdio.h>


int main()

{

    for(int i = 100; i <= 200 ; i++)

  if(i%4==2&&i%7==3&&i%9==5)

   printf("%d\n",i);

  return 0;





用选择法对10个整数排序:


#include <stdio.h>

Void main()

{

Int *p,i,a[10];

P=a;

For (i=0;i<10;i++)

Scanf (


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值