赞
踩
- int main() {
- int a = 0;
- int b = 0;
- int c = 1;
- int n = 0;
- for(n=1; n <=4;n++)
- {
- c = 1;
- for (a = 1;a <= n; a++)
- {
- c *= a;
- }
-
- b += c;
- }
-
- printf("%d", b);
-
- return 0;
- }
- int main() {
-
- int arr [] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- int k = 7;
- int left = 0;
- int sz = sizeof(arr) / sizeof(arr[0]);
- int right = sz-1;
-
- while (left <= right)
- {
- int mid = (left + right) / 2;
- if (arr[mid] < k) {
-
- left = mid + 1;
- }
- else if (arr[mid] > k) {
- right = mid - 1;
- }
- else {
- printf("找到了,下标是%d", mid);
- break;
-
- }
- }
- if(left>right)
- {
- printf("找不到了");
-
- }
- return 0;
- }
- int main() {
- int i = 0;
- char password[20] = { 0 };
- for (i = 0; i < 3; i++)
- {
- printf("请输入密码:");
- scanf("%s", password);
- if (strcmp(password, "12345") == 0)
- {
- printf("登录成功");
- break;
- }
- else
- {
- printf("密码错误,请重新输入\n");
- }
-
- }
- if (i == 3)
- printf("三次密码输入错误,退出程序");
-
- return 0;
- }
- void game() {
- int ret = rand()%100+1;
- int guess = 0;
- while (1)
- {
- printf("请猜1~100的数字\n:>");
- scanf("%d", &guess);
-
- if (guess < ret) {
- printf("猜小了\n");
- }
- else if (guess >ret){
- printf("猜大了\n");
- }
- else {
- printf("恭喜你猜对了!\n");
- break;
- }
-
- }
-
- }
-
- void begin() {
- printf("*****1.开始游戏*****\n");
- printf("*****0.退出游戏*****\n");
- }
- int main() {
-
- int input = 0;
- srand((unsigned int)time(null));
-
- do
- {
- begin();
- printf("请选择:>");
- scanf("%d", &input);
- switch (input)
- {
- case 1:
- game();
- case 0:
- printf("退出游戏\n");
- break;
- default:
- printf("请重新选择\n");
- break;
- }
-
- } while (input);
-
-
- return 0;
-
- }
- /*
- int is_leap_year(int a) {
- if (a % 4 == 0 && a % 100 != 0)
- {
- return 1;
- }
- else if (a % 400 == 0)
- {
- return 1;
- }
- else
- return 0;
- }
- int main() {
- int count = 0;
- int y = 0;
- for (y = 1000;y < 2000;y++)
- {
-
- if (is_leap_year(y) == 1)
- {
- count++;
- printf("%d\n", y);
- }
-
- }
- printf("总数=%d\n", count);
- return 0;
- }
- void my_strcpy(char *arr1,char *arr2) {
- while(*arr1++ = *arr2++){
- }
- }
- int main() {
- char arr1[] = { "1234578" };
- char arr2[] = { "xx0108" };
- my_strcpy(arr1, arr2);
- printf("% s \n", arr1);
-
- }
- int main() {
- int arr1[10] = { 1,2,3,4,5,6,7,8,9,10 };
- int arr2[10] = { 0 };
- memcpy(arr2, arr1, 21);
-
- return 0;
- }
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- 12321;
- long ge, shi, qian, wan, x;
- scanf("%ld", &x);
- wan = x / 10000;
- qian = x % 10000/1000;// X/1000 % 10 都可以
- shi = x / 10 % 10;
- ge = x % 10;
- if (wan == ge && qian == shi)
- {
- printf("%ld\n%ld\n%ld\n%ld\n%ld是回文数\n", x,wan,qian,shi,ge);
- }
- else
- {
- printf("%ld\n%ld\n%ld\n%ld\n%ld不是回文数\n", x, wan, qian, shi, ge);
- }
- return 0;
- }*/
- #include <stdio.h>
- #define m 50
- void main()
- {
- int a[m],c[5] = { 0 }, i, n = 0,x;
- printf("请输入0~4范围内的整数(最多输入50个),以-1结束\n");
- scanf("%d", &x);
- while (x != -1)
- {
- if (x >= 0 && x <= 4)
- {
- a[n] = x;
- n++;
- }
- scanf("%d", &x);
- }
- for (i = 0; i < n; i++)
- {
- c[a[i]]++;
- }
- printf("每个整数的个数是:\n");
- for (i = 0;i <= 4;i++)
- {
- printf("%d:%d\n", i, c[i]);
- }
-
- */
- }
- #include <stdio.h>
- void main() //1~9 乘法表
- {
- int i, j ,sum = 0;
- for (j = 1;j<=9;j++)
- {
- for (i = 1;i <= j;i++)
- {
- sum = i * j;
- printf("%d * %d = %d"" ",i, j, sum);
- }printf("\n");
- }
- }
- #include <stdio.h>
- #include <string.h>
- #define N 50
- void main() 输入一组字符串以空格为间隔,判断单词数量
- {
- char str[N];
- int num = 0;
- int i = 0;
- int word = 0;
- printf("请输入一组字符串,可用空格作为间隔:\n");
- gets(str);
- for (i = 0;i < N && str[i] != '\0'; i++)
- {
- if (str[i] == ' ')
- {
- word = 0;
- }
- else
- {
- word = 1;
- num = num + word;
- }
- }
- printf("单词个数为:%d", num);
- }
- #include <stdio.h>
- void main()
- {
- char a[5][10] = { "one","two","three","four","five" };//定义一个二维字符数组,简单赋值
- int i, j;//用作下面循环的变量
- char t;//用作交换的中间变量
- for (i = 0;i < 4;i++)//冒泡法的标准格式,详见下面
- for (j = i + 1;j < 5;j++)
- {
- t = a[i][0];
- a[i][0] = a[j][0];
- a[j][0] = t;
- }
- puts(a[1]);//输出交换后的第二个字符串
- }
- #include <stdio.h>
- int main() {
- int a = 0;
- scanf("%d", &a);
- if (a % 3 == 0 && a % 5 == 0)
- {
- printf("yes");
- }
- else
- {
- printf("no");
- }
- return 0;
- }
- #include <stdio.h>
- int main() {
- /*int men = 0, women = 0, kid = 0;
- (men + women + kid) == 36;
- (4 * men + 3 * women + kid/2) == 36;
- printf("男人:%d女人:%d小孩:%d", men, women, kid);*/
- int men, women, children;
- for (men = 0;men < 9;men++)
- {
- for (women = 0;women < 12;women++)
- {
- children = 36 - women - men;
- if ((4 * men + 3 * women + children / 2) == 36 && children % 2 == 0)
- {
- printf("男人:%d个\n女人:%d个\n小孩:%d个\n", men, women, children);
- }
- }
- }
- return = 0;
- }
- #include <stdio.h>
- int main() {
- int i,n,all=0,sum = 1;
- scanf("%d", &n);
- for (i = 1;i <= n;i++)
- {
- sum = sum * i;
- all = all + sum;
- }
- printf("%d", all);
-
- return 0;
- }
- #include <stdio.h>
- //#define N 100
- int main()
- {
- char c;
- int words = 0, spaces = 0, nums = 0,others=0;
- while((c=getchar())!='\n')
- {
- if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
- {
- words++;
- }
- else if (c == ' ')
- {
- spaces++;
- }
- else if (c >= '0' && c <= '9')
- nums++;
- else
- others++;
- }
- printf("英文字母=%d\n空格=%d\n数字=%d\n其他字符=%d\n", words, spaces, nums, others);
- return 0;
- }
- #include <stdio.h>
- #include<math.h>
- int main()
- {
- int x,y,z;
- printf("请输入两个整数:\n");
- scanf(" %d%d", &x, &y);
- z=abs(x - y);
- printf("%d", z);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int a,b,i,total=1,rear=0;
- char x[3] = { 0 };
- printf("请输入两个整数:\n");
- scanf(" %d%d", &a, &b);
- for (i = 1;i <= b;i++)
- {
- total = total * a;
- }
- rear = total % 1000;
- if(rear % 100 == 0 && rear % 1000 == 0 )
- {
- x[0] = '0';
- x[1] = '0';
- printf("%d\n%s%d",x,rear);
- }
- else if (rear % 1000 == 0)
- {
- x[0] = '0';
-
- printf("%d\n%s", x,rear);
- }
- else
- {
- printf("%d\n%d", rear);
- }
-
- return 0;
- }
-
- #include <stdio.h>
- int main()
- {
- int a, b, i, total = 1;
- printf("请输入两个整数:\n");
- scanf(" %d%d", &a, &b);
- for (i = 1;i <= b;i++)
- {
- total = total * a;
- total = total % 1000;
- }
- printf("%03d\n", total);
- return 0;
- }
- #include <stdio.h>
- #define N 100
- int main()
- {
- int i=0;
- char a[N] = {0};
- gets(a);
- while (a[i] != '\0')
- {
-
- if (a[i] >= 'A' && a[i] <= 'Z' || a[i] >= 'a' && a[i] <= 'z')
- {
- a[i] = a[i] + 4;
- }
- i++;
- }
- printf("%s", a);
- }
- #include <stdio.h>
- int main()
- {
- float a=0;
- scanf("%f", &a);
- if (a < 60 )
- {
- printf("成绩为:E");
- }
- else if (a >= 60 && a < 70)
- {
- printf("成绩为:D");
- }
- else if (a >= 70 && a < 80)
- {
- printf("成绩为:C");
- }
- else if (a >= 80 && a < 90)
- {
- printf("成绩为:B");
- }
- else if (a >= 90 && a < 100)
- {
- printf("成绩为:A");
- }
- return 0;
- }
- #include<stdio.h>
- int newabs(int x, int y)
- {
- if (x > y)
- {
- return x - y;
- }
- else
- return y - x;
- }
- int main()
- {
- printf("%d", newabs(2, -3));
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- char a='0';
- scanf("%c",&a);
- if (a >= 'a' && a <= 'z')
- {
- a = a - 32;
- }
- else if (a >= 'A' && a <= 'Z')
- {
- a = a + 32;
- }
-
- printf("%c\n", a);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int a[10] = {1,2,3,4,5,6,7,8,9,10};
- int i = 0,x=0,sum=0;
- for(i=0;i<10;i++)
- {
- if (a[i] % 2 == 0)
- {
- x++;
- sum = sum + a[i];
- }
-
- }
- printf("偶数个数:%d\n偶数平均值:%d", x, sum / x);
- return 0;
- }
- #include<stdio.h>
- int main()
- {
- int a=0, b=0,sum=0;
- char ope='0';
- printf("依次输入两个数和一个运算符(逗号相隔)\n");
- scanf("%d,%d,%c", &a, &b,&ope);
- switch (ope)
- {
- case '+':
- sum = a + b;
- break;
- case '-':
- sum = a - b;
- break;
- case '*':
- sum = a * b;
- break;
- case '/':
- sum = a / b;
- break;
- default:
- break;
- }
- printf("%d\n运算结果为:", sum);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int sum = 1, n = 0;
- for (n = 0;sum < 200;)
- {
- n++;
- sum = sum * n;
- }
- do {
- n++;
- sum = sum * n;
- } while (sum < 200);
- printf("n的值是:%d\nn阶乘的值是:%d", n, sum);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int a, b, c,t;
- printf("请输入3个数:\n");
- scanf("%d%d%d", &a, &b, &c);
- if (a > b) {
- t = a;a = b;b = t;
- }
- if (a > c) {
- t = a;a = c;c = t;
- }
- if (b > c) {
- t = b;b = c;c = t;
- }//三个数排序完成
-
- printf("%d<=%d<=%d", a, b, c);
-
-
- return 0;
- }
- #include<stdio.h>
- int main()
- {
- int i,ge,shi,bai,n=0;
- for (i = 100;i < 1000;i++)
- {
- if( i % 11 == 0)
- {
- ge = i % 10;
- shi = i/10 % 10;
- bai = i /100 ;
- if (ge != shi && shi != bai && ge != bai)
- {
- printf("%d\n", i);
- n++;
- }
- }
- }printf("满足条件的数共有%d个", n);
- return 0;
- }
- #include<stdio.h>
- int main()
- {
- char a[5][50], * sp;
- int i;
- for (i = 0;i < 5;i++)
- {
- gets(a[i]);
- }
- sp = a[0];
- for (i = 1;i < 5;i++)
- {
- if (strlen(sp) < strlen(a[i]))
- {
- sp = a[i];
- }
-
- }printf("\n最长的字符串是:%s", sp);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int b,n=0;
- char a;
- for (a = 'A';a <= 'Z';a++)
- {
- b = a;
- printf("%d ", b);
- n++;
- if (n == 3)
- {
- printf("\n");
- n = 0;
- }
- }
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int month_day[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
- int i, year, month, day, * p;
- p = month_day;
- printf("请输入年-月-日:\n");
- scanf("%d-%d-%d", &year, &month, &day);
- for (i = 1;i < month;i++)
- {
- day = day + p[i];
- }
- if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
- {
- day++;
- }
- printf("该日是%d年的第%d天", year, day);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int x, y, z = 0;
- scanf("%d%d", &x, &y);
- z = (x % y);
- printf("%d", z);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int sum=0,t,ge,shi,bai,qian,i = 0;
- for (i = 10;i <= 1993;i++)
- {
- if (i < 100)
- {
- ge = i % 10;
- shi = i / 10 % 10;
-
- if (ge == shi)
- {
- printf("%d ", i);
- sum++;
- }
- }
- if (i>=100 && i < 1000)
- {
- ge = i % 10;
- shi = i / 10 % 10;
- bai = i / 100 % 10;
- t = bai;
- bai = ge;
- ge = t;
- if (ge == bai)
- {
- printf("%d ", i);
- sum++;
- }
- }
- if (i >= 1000 && i < 1993)
- {
- ge = i % 10;
- shi = i / 10 % 10;
- bai = i / 100 % 10;
- qian = i / 1000;
- t = qian;
- qian = ge;
- ge = t;
- t = bai;
- bai = shi;
- shi = t;
- if (ge == qian && shi==bai)
- {
- printf("%d ", i);
- sum++;
- }
- }
-
- }printf("满足条件的对称数有:%d个 ", sum);
- return 0;
- }
- #include <stdio.h>
- int main()
- {
- int a, d, i, x,sum=0;
- for (i = 10;i <= 1993;i++)
- {
- a = i;x = 0;
- while (a != 0) //a最后被拆光等于0了跳出循环
- {
- d = a % 10; //每次把末尾的数拆下来
- x = x * 10 + d;//把拆下来的数赋给x
- a = a / 10;//把a值缩小10倍
- }
- if (x == i)//将原数值i和颠倒后的x对比
- {
- printf("%d\t", x);
- sum++;
- }
- }printf("总计:%d\n",sum);
- return 0;
- }
- #include <stdio.h>
- #define N 5
- int main()
- {
- int a[N] = {0};
- int i,x,t;
- for (i = 0;i < N;i++)
- {
- scanf("%d", &a[i]);
- }
- for (i = 0;i <N/2;i++)
- {
- t = a[i];
- a[i] = a[N - i - 1];
- a[N - i - 1] = t;
- }
- for (i = 0;i < N;i++)
- {
- printf("%d ", a[i]);
- }
- return 0;
- }
- #include<stdio.h>
- int main()
- {
- int a[6] = { 92,85,66,89,95,79 };
- int max = a[0], min = a[0],i,sum=0;
- float aver;
- for (i = 1;i <= 5;i++)
- {
- if (max < a[i])
- max = a[i];
- if (min > a[i])
- min = a[i];
- }
- for (i = 0;i <= 5;i++)
- {
- sum = sum + a[i];
- }
- aver = (float)(sum - max - min) / 4;
- printf("%.2f", aver);
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。