Initial commit: C language learning code
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
int n=0;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
n++;
|
||||
x=x/10;
|
||||
while(x>10)
|
||||
{
|
||||
n++;
|
||||
x=x/10;
|
||||
}
|
||||
printf("%d\n",n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int number;
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
|
||||
printf("请输入数字\n");
|
||||
scanf("%d", &number);
|
||||
while(number!=-1)
|
||||
{
|
||||
sum = sum+number;
|
||||
count = count+1;
|
||||
printf("请输入数字\n");
|
||||
scanf("%d", &number);
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
printf("平均数是%.2f\n", (float)sum / count);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("未输入有效数字\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
srand(time(0));
|
||||
int number = rand()%100+1;
|
||||
int count = 0;
|
||||
int a = 0;
|
||||
printf("我已经想好了一个1到100之间的数。");
|
||||
|
||||
do
|
||||
{
|
||||
printf("请猜这个1到100之间的数:");
|
||||
scanf("%d", &a);
|
||||
count = count+1;
|
||||
|
||||
if(a>number)
|
||||
{
|
||||
printf("你猜的数大了。");
|
||||
}
|
||||
else if(a<number)
|
||||
{
|
||||
printf("你猜的数小了。");
|
||||
}
|
||||
}
|
||||
while(a != number);
|
||||
|
||||
printf("太好了,你用了%d次就猜对了。\n", count);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
scanf("%d", &x);
|
||||
|
||||
int number;
|
||||
int renum=0;
|
||||
|
||||
while(x>0)
|
||||
{
|
||||
number = x%10;
|
||||
printf("%d", number);
|
||||
renum = renum*10+number;
|
||||
printf("x=%d, number=%d,renum=%d\n", x, number, renum);
|
||||
x/=10;
|
||||
}
|
||||
printf("%d", renum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user