C语言1-100连加,求质数,算瑞年检测字母大小写,登录系统

#include <stdio.h>

void test(){//1+2+3+4+.....+100

    int a,b;

    a=0;

    b=0;

    for ( ; a<=100; a++) {

        b=b+a;

        printf("%d ",b);

    }

}

void test1(){//输入一个数,看一下是不是质数

    int c;

    printf("请输入一个大于10的数字:");

    scanf("%d",&c);

    printf("In checking,wait a minuts.please ");

    if (c%2!=0&&c%3!=0&&c%5!=0&&c%7!=0)

        printf("%d 是质数 ",c);

    else printf("%d 不是质数",c);

}

/*求质数easier

#include<stdio.h>

#include<math.h>

 int main()

 {int n,i,k;

 printf("please enter a integer number:n=?");

 scanf("%d",&n);

 k=sqr(n);

 for(i=2;i<=k;i++)

   if(n%i==0)break;

 if(i<=k)printf("%d is not a prime number. ");

 return 0;

  }

 */

void test2(){//打印8~100以内的质数

    int d=8;

    while (d<100) {

        if (d%2!=0&&d%3!=0&&d%5!=0&&d%7!=0)

            printf("%d 是质数 ",d);

        printf("%d 不是质数",d);

        d++;

    }

    printf(" ");

}

void test3(){//输入一个年份,看看是不是瑞年

    int e;

    printf("请输入所要检测的年份:");

    scanf("%d",&e);

    printf("In checking,wait,please... ");

    if (e%100==0) {//if

        if (e%400==0)

            printf("%d年是瑞年 ",e);

          else  printf("%d年不是瑞年 ",e);

            }

        else if (e%4==0)

            printf("%d 年是瑞年 ",e);

         else   printf("%d 年不是瑞年 ",e);

}

void test4(){//随机输入一个字母,判断该字母是大写还是小写,并输出相应的大写或者小写字母

    char f;

    printf("请输入一个字母 ");

   //f=getchar();

    scanf("%c",&f);

    printf("wait ");

    while (f!=' ') {

        if (f>='a'&&f<='z') {

            printf("%c 是小写字母 ",f);

            printf("%c 的大写字母是 %c ",f,f-32);

        }

        if (f>='A'&&f<='Z') {

            printf("%c 是大写字母 ",f);

            printf("%c 的小写字母是 %c ",f,f+32);

        }

    }

}

/*大小写

 printf("%d-%d-%d-%d",'a','z','A','Z');//输出对应ASIC码

 if(a>=97&&a<=122){

 printf("ta是一个小写字母,对应大写:%c",a-32)

 }

 else if。。。

 */

void test5(){//登陆系统

    int g,h,i,j;

    i=1;

    j=1;

    printf("请输入用户名:");

    scanf("%d",&g);

    printf("请输入密码:");

    scanf("%d",&h);

    if (g==i&&h==j)

        printf("dengluchenggong ");

   else printf("denglushibai ");

    

}

/*登陆程序且可以重复运行。

 int name=0,pass=0;

 int c_name=123,c_pass=456;

 while(1){

 printf("qingshuruyonghuming: ");

 scanf("%d",&name);

 printf("qingshurumima: ");

 scanf("%d",&pass);

 if(!(name==c_name&&pass==c_pass)){

 printf("输入信息不正确 ");

 }

 else{break;}

 }printf("登陆成功");

 */

int main(int argc, const char * argv[]) {

    // insert code here...

    printf("Hello, World! ");

    test();

    test1();

    test2();

    test3();

    test4();//可独立运行

    test5();

    return 0;

}

原文地址:https://www.cnblogs.com/OIMM/p/4695697.html