首页 > 代码库 > 课堂作业

课堂作业

#include<stdio.h>
int main()
{
  //for

  int i,sum=0;
  for(i=1;i<=100;i++)
    sum += i;

  printf("sum = %d\n",sum);
  //while
  sum=0;
  while(1<=100){
    sun=sum+i;
    i++;
  }
  printf("sum=%d\n",sum);
  return 0;
}

技术分享

 

 

 

 

 

#include<stdio.h>
int main(){
  int n,i,jiec=1;
  printf("ÇëÊäÈëÒ»¸öÕûÊýn:");
  scanf("%d,&n");
  i=n;
  while(i>=1){
    jiec = jiec*i;
    i--;
  }
  printf("%d!=%d\n,n,jiec");
  return 0;
}

技术分享

 

 

 

#include<stdio.h>
int main(){
  i=n; jiec = 1;
  while(i<=n){
  jiec = jiec * i;
  i++;
  }
  printf("%d!=%d\n",n,jiec);
  return 0;
}

 

 

#include<stdio.h>int main(){    char c;    int zm=0,sz=0,kg=0,qt=0;    while((c=getchar())!=\n{        if(c>=a&&c<=z || c>=A&&c<=Z)        zm++;        else if(c==‘‘)        kg++;        else         qt++;    }    printf("×Öĸ¸öÊý:%d\n",zm);    printf("¿Õ¸ñ¸öÊý:%d\n",kg);    printf("Êý×Ö¸öÊý:%d\n",kg);    printf("ÆäËû¸öÊý:%d\n",kg);    return 0;}

 

 

 



 

 

 

 

#include<stdio.h>int main(){    int m,n,t,i;    printf("ÇëÊäÈëÁ½¸öÕûÊý:");    scanf("%d%d",&m,&n);    if(n>m){        t=m;        m=n;        n=t;    }    for(i=n;i>=1;i--)       if(m%i==0&&n%i==0)               break;        printf("m=%d,n=%d",m,n);    if(i!=0)        printf(",×î´ó¹«Ô¼ÊýΪ:%d",i);        return 0;        }

技术分享

 

 

 

 

 

#include<stdio.h>int main(){    int n,k1,k2,k3;    for(k1=0;k2<=9;k1++)        for(k2=0;k2<=9;k2++)            for(k3=1;k3<=9;k3++){                if(k3*100+k2*10+k1==k1*k1*k1+k2*k2*k2+k3*k3*k3)                    printf("%d\n",k3*100+k2*10+k1);            }            return 0;}

 

课堂作业