C_使用switch语句
源码:
# include <stdio.h>
int main()
{
int num;
/* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
int indiv, ten, hundred, thousand;
int ten_thousand, hundred_thousand, place;
printf("请输入一个整数(0~999999):");
scanf("%d", &num);
/* 判断变量num的位数 */
if(num > 99999)
place = 6;
else if(num > 9999)
place = 5;
else if(num > 999)
place = 4;
else if(num > 99)
place = 3;
else if(num > 9)
place = 2;
else
place = 1;
printf("place = %d\n", place);
printf("每位数字为:");
/* 求出num在各位上的值 */
hundred_thousand = num/100000;
ten_thousand = (num - hundred_thousand*100000)/10000;
thousand = (num - hundred_thousand*100000 - ten_thousand*10000)/1000;
hundred = (num - hundred_thousand*100000 - ten_thousand*10000
- thousand*1000)/100;
ten = (num - hundred_thousand*100000 - ten_thousand*10000
- thousand*1000 - hundred*100)/10;
indiv = num - hundred_thousand*100000 - ten_thousand*10000
- thousand*1000 - hundred*100 - ten*10;
/* 判断变
相关文档:
#include <stdio.h>
#define MAX 100
int a[MAX], b[MAX], count = 0;
void rData()
{ int i;
FILE *fp;
fp = fopen("C:\\100.dat", "r");
for (i=0; i<MAX; i++)
fscanf(fp, "%d,", &a[i]);
fclose(fp);
}
void main()
{ int i;
rData();
//printf("满足条件的数= ......
源码:
# include <stdio.h>
int main()
{
int i, j, k;
int m, n, p;
i = 8;
j = 10;
k = 12;
/* 自增在操作数之前 */
  ......
源码:
# include <stdio.h>
int main()
{
/* 定义字符型变量,并给它们付初值 */
char c1, c2, c3, c4, c5, c6, c7;
c1 = 'C';
c2 = 'h';
c3 = 'i';
c4 = 'n';
& ......
源码:
# include <stdio.h>
int main()
{
/* 定义一个整形指针p */
int *p;
int begin, end;
begin = 10;
/* 给指针p赋初值 */
p = &begin;
& ......
源码:
# include <stdio.h>
int main()
{
int x, y, z, mid, dec;
printf("请任意输入三个整数:\n");
scanf("%d %d %d", &x, & ......