while迴圈簡易問題及最佳化代碼

來源:互聯網
上載者:User

標籤:c語言基本學習

/*#include<stdio.h>int main()  {        int i,x,y;        scanf("%d",&i);     for(x=1;x<=sizeof(i);x++)    {       while(i>0)       {          y=i%10;           i=i/10;         printf("%d ",y);         }     }  printf("\n");   return 0; } *//*#include<stdio.h> int main(){   int i,a,x=0,count=0;    for(i=1;i<=100;i++)   {      int a=i;  while(a>0)    {        x=a%10;        a=a/10;        if(x==9)        count++;      }    }   printf("%d\n",count);   return 0;}*/求最大公約數/*#include<stdio.h>int main(){   int i,a,b;   scanf("%d %d",&a,&b); if(a>b)    i=b;  else    i=a;    for(i;i>=2;i--)   {       if(a%i==0&&b%i==0)         break;    }    printf("%d\n",i);  return 0;}*/大寫換小寫,小寫換大寫,數字不換,Ctrl+Z跳出/*#include<stdio.h>int  main(){   char c,s;  c=getchar();   while(c!=EOF)   {       if(c>=‘a‘&&c<=‘z‘)       {         s=c-32;           printf("%c\n",s);         }      else       if(c>=‘A‘&&c<=‘Z‘)          {           s=c+32;           printf("%c\n",s);         }     else if(c>=‘0‘&&c<=‘9‘)         {  s=c;          printf("%c\n",s);           }            c=getchar();     }     return  0;}*/用指標比大小/*#include<stdio.h>int main(){  int a=2,b=3;   int *pa,*pb;   pa=&a;   pb=&b;  printf("%d %d \n%d %d\n",a,b,*pa,*pb);    return 0;}*//*#include<stdio.h>   int main()   {       int a,b;        int *pa,*pb;       scanf("%d%d",&a,&b);        pa=&a;       pb=&b;         if(a<b)          {           int *tmp=pa;           pa=pb;           pb=tmp;           }       printf("%d  %d  %d   %d\n",*pa,*pb,a,b);       return 0;    }*/ /*#include<stdio.h>   void swap(int *a,int *b)       {           if(*a<*b)              {               int tmp=*a;                *a=*b;                  *b=tmp;                   }         }   int main()   {        int a,b;         int *pa,*pb;      scanf("%d%d",&a,&b);        pa=&a;          pb=&b;           swap(pa,pb);         return 0;    }*/輾轉相除求最大公約數/*#include<stdio.h> int main(){    int a,b,i;   scanf("%d%d",&a,&b);  if(a<b)     {       i=a;       a=b;       b=i;       }      if(a%b==0)        printf("%d",b);        else              {                while(a%b!=0)                {                      i=a%b;                      a=b;                      b=i;                 }                 printf("%d\n",i);                }                 return 0;    }*/


本文出自 “小止” 部落格,請務必保留此出處http://10541556.blog.51cto.com/10531556/1675771

while迴圈簡易問題及最佳化代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.