C语言第三节课

把两个数的值互换:

 #include <stdio.h>

main()
{
int a,b,c=0;
printf("请输入两个整数:\n");
scanf("%d%d",&a,&b);
printf("a=%d,b=%d",a,b);
c=a;a=b;b=c;
printf("a=%d,b=%d",a,b);
}
 
小写字母变大写字母:
#include <stdio.h>
main()
{
int d=32;
    char ch1,ch2,ch3;
    printf("input three better:");
    ch1=getchar();
    ch2=getchar();
    ch3=getchar();
    ch1=ch1-d;
    ch2=ch2-d;
    ch3=ch3-d;
    ch1=ch1>'z'?ch1-26:ch1;
    ch2=ch2>'z'?ch2-26:ch2;
    ch3=ch3>'z'?ch3-26:ch2;
    putchar(ch1);
    putchar(ch2);
    putchar(ch3);
 
    getch();
}
 
 
判断大小:
#include <stdio.h>
main()
{
  int a,b,min;
  printf("请输入两个整数:");
  scanf("%d%d",&a,&b);
  if(a>b) min=b;else min=a;
\\三目运算的话, a>b ? printf("%d",b);:printf("%d",a);
  printf("最小的数是%d",min);
 
}
 
 
求三位数的百位、十位、个位之和:
#include <stdio.h>
main()
{
 int a,b,c,n,s;
 printf("input numbers:");
 scanf("%d",&n);
 a=n%10;
 c=n/100;
 b=n%100/10;
 s=a+b+c;
 printf("%d",s);
    getch();
}
 
 

 

你可能感兴趣的:(职场,C语言,include,休闲,小写字母变大写字母)