#Include Main (Float S, N Int T T 1 For (N 1 N 100 N++) (S S+T N/ (n+1) T T (-1) ) Printf ("SUM %F",S) Return 0 )

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

ฝึ กเขียนโปรแกรมภาษาซี

เฉลยแบบฝึ กหัด
#include <stdio.h>
  main(){
  float s,n;
  int t;
  t=1;
  for(n=1;n<100;n++)
 {
   s=s+t*n/(n+1);
  t=t*(-1);
 }
  printf("SUM=%f",s);
  return 0;
 }
เฉลยแบบฝึ กหัด

#include <stdio.h>
 main()
 {
 int a,b,c;
 a=1;
 b=1;
 c=1;
 while(a<4){
            if(a!=b && b!=c && c!=a) {printf("%d%d%d\n",a,b,c);}
            c++;
            if(c==4){
                     c=1;
                     b++;
                     if(b==4){
                             b=1;
                             a++;
                             }
          }
 }
 printf("\n\ninput anything and press ENTER to Exit..");
 scanf("%d");
 return 0;
 }
เฉลยแบบฝึ กหัด
#include <stdio.h>
 main(){
        int a,b;
        for(a=0;a<10;a++){
                          for(b=9-a;b!=0;b--){
                                              printf(" ");
                       }
                          for(b=0;b!=a;b++){
                                            printf("*");
                      }
                          if(a==0)printf("*");
                          else printf("%d",a);
                          for(b=a;b>0;b--){
                                           printf("*");
                                           }
                          printf("\n");
             }
        for(a=8;a>=0;a--){
                          for(b=9-a;b!=0;b--){
                                              printf(" ");
                       }
                          for(b=0;b!=a;b++){
                                            printf("*");
                      }
                          if(a==0)printf("*");
                          else printf("%d",a);
                          for(b=a;b>0;b--){
                                           printf("*");
                                           }
                          printf("\n");
             }
 printf("\n\ninput anything and press ENTER to Exit..");
 scanf("%d");
 return 0;
 }

You might also like