다른공부/C언어

c언어 교양 20160412

요카지마 2016. 4. 12. 09:49
반응형

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      sin(30*3.14/180);
     
      int d;
      double s, pi=3.1415;
      for(d=0;d<=360;d+=15)
      {
      s=sin(d*pi/180) ;//s는 sin값
          printf("sin(%3d)=%+.2f \n",d,s);
          }
          system("pause");
     
      }

싸인그래프

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      sin(30*3.14/180);
     
      int d,b,i;
      double s, pi=3.1415;
      for(d=0;d<=360;d+=15)
      {
      s=sin(d*pi/180) ;//s는 sin값
          printf("sin(%3d)=%+.2f ",d,s);
          b=(s+1)*10;
          for(i=0;i<=b;i++)
          printf(" ");
          printf("*\n");
          }
          system("pause");
     
      }

 

시험문제 이렇게 쉽게 안나온다

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      int d,s=0;

      for(d=1;d<=5;d+=1)
          {
          s+=d;
          }
          printf("%d %d",d,s);
          system("pause");
     
      }

이정도로는 나온다

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      int d,s=0;

      for(d=1;d<=5;d+=1)
          {
          s+=d;
          d++;
          }
          printf("%d %d",d,s);
          system("pause");
     
      }

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      int d,s=0;

      for(d=1;d<=5;d+=1)
          {
          d++;//
          s+=d;//2 4 6
          }
          printf("%d %d",d,s);
          system("pause");
     
      }

 

시험문제는  while for 바꿔쓰기

연산자랑 if 바꿔쓰기

 

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      int i,s;
      for(i=1,s=0;i<=10;i++)
      {
      if (i==5)
      continue;
      s+=i;
      }
          printf("%d %d",i,s);
     
          system("pause");
     
      }

//s=1 3 6 10 16 23 31 40 50
//i=1 2 3 4 5 6 7 8 9 10 11

 

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
      int i,n,mult=1;
      do
      {printf("수 입력(1-10) ");
      scanf("%d",&n);
      }
      while ((1>n)|| (10<n)); // 1보다 작거나 10보다  크면 다시입력
      for(i=1;i<=n;i++)
      mult*=i;
      printf("1부터 %d까지 곱 %d\n",n,mult);
          system("pause");
     
      }

반응형

'다른공부 > C언어' 카테고리의 다른 글

c언어 교양 20160414  (0) 2016.04.14
c언어 교양 중간고사 범위  (0) 2016.04.14
c언어 교양 20160407  (0) 2016.04.07
c언어교양 20160405  (0) 2016.04.05
c언어 교양 20160331  (0) 2016.03.31