c/c++语言开发共享C语言学习之路之五————C语言小程序

  c语言程序 1. 九九乘法表(利用数组)  #include <stdio.h> int main(void){  &nbsp

  c语言程序
1. 九九乘法表(利用数组)
 #include <stdio.h>
int main(void){
      int a [9];
      int c [9];
      int x;
      int y;
  for(x=1;x<=9;x++){
         a[x]=x;
}
for(y=1;y<=9;y++){
          c[y]=y;
}
       for(x=1;x<=9;x++){
              for(y=1;y<=x;y++){
                       printf("%d * %d=%d",a[x],c[y],a[x]*c[y]);
               }
                  printf("n");
       }
                           return 0;
}

2.水仙花数的实现
 #include <stdio.h>
  int main(void){
   int a,b,c,sum;
    for(a=1;a<=9;a++){
            for(b=0;b<=9;b++){
                     for(c=0;c<=9;c++){
                               sum=a*100+b*10+c;
                                      if(sum==a*a*a+b*b*b+c*c*c){
                                         printf("%dn",sum);
                                }
                    }
            }
      }
       return 0;
 }
3.一个银行的密码输入,限制输入次数(do ..while语句)
#include <stdio.h>
int main(void){
          int password;
          int count=0;
          printf("您的密码只能输入三次,超过三次将被锁住!n");
      do{
                 if(count<3){
                 printf("输入您的密码:n");
                 scanf("%ld",&password);
                 printf("密码错误,在想想n");
                 }
                 else if(3==count){
                  printf("密码错误,卡以被锁!");
             }
                  count++;
     }
     while(123456!=password);
               printf("进入银行系统!!");
}

4. 一个数加上100是一个平方数再加上168还是一平方数求这数。。
#include <stdio.h>
int main(void){

long int i,x,y;
      for(i=1;i<100000;i++){
      x=sqrt(i+100);
      y=sqrt(i+268);

  if(x*x==i+100&&y*y==i+268)
     printf("n%ldn",i);
  }
}

5.输入两个数求平均值
#include <stdio.h>
int main(void){
int count,sun,aninteger;
printf("enter the inteegers and terminate with negtive numbern");
count =0;
sun=0;
printf("enter number %d:",count+1);
scanf("%d",&aninteger);
while(aninteger>=0){
sun+=aninteger;
count++;
printf("enter number %d:",count+1);
    scanf("%d",&aninteger);
}if(count!=0){
printf("the average is %fn",sun/(double)count);
}else{
printf("you enteed no numbersn");
}
return 0;
} 

摘自 10-3g-何进超 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/603908.html

(0)
上一篇 2021年5月12日
下一篇 2021年5月12日

精彩推荐