Thread: C program Degree to Radians

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    Question C program Degree to Radians

    How would you do this c program, I'm a beginner I'm just starting with C, and i can't figure out how to finish the middle part.

    Complete the following C program that first reads a, b, c, where a and b are two degrees and c is increment. The program then generates a table of conversions from degrees to radians. Start degrees at a and increment by c until the degree is greater than b.
    Recall that we say 180o is equal to π radian.
    You can assume that π is 3.14.


    Code:
    #include <stdio.h>
    #define PI 3.14
    int main(void)
    {
    
    int a,b,c, degree;
    
    
    /* Enter the start degree, end degree, and increment */
    
    printf("Enter a b c : ");
    scanf("%d %d %d", &a, &b, &c);
    
    for (i=a;i<=b;i=i+c)
    {
    printf("degree Radian");
    printf(" %d %f", i, i*3.14/180);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    system("pause");
    /* Exit program. */
    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What is it you can't do? The math?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    37
    Quote Originally Posted by quzah View Post
    What is it you can't do? The math?


    Quzah.
    i don't know what to do after this part:

    Code:
    for (i=a;i<=b;i=i+c)
    {
    printf("degree Radian");
    printf(" %d %f", i, i*3.14/180);
    }

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Pretty much worked for me. I had to add
    int i;
    ... and also a "\n" in the printf to generate separate lines. That's about it.

    You might want to use your constant PI since you defined it.

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Wel you were almost there. There weren't any much changes. Apart from the few things which nonood had mentioned. Maybe one thing which you should look at is the intendation.

    Code:
    #include <stdio.h>
    #define PI 3.14
    
    int main(void)
    {
       int a,b,c, degree;
       int i;
       
       printf("Enter a b c : ");
       scanf("%d %d %d", &a, &b, &c);
    
       for (i=a; i<=b; i=i+c)
       {
          printf("degree Radian: ");
          printf("%d - %f\n", i, (i * 3.14) / 180);
       }
       
       system("pause"); 
       return 0;
    }
    -ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Cyberman86 View Post
    How would you do this c program, I'm a beginner I'm just starting with C, and i can't figure out how to finish the middle part.

    Complete the following C program that first reads a, b, c, where a and b are two degrees and c is increment. The program then generates a table of conversions from degrees to radians. Start degrees at a and increment by c until the degree is greater than b.
    Recall that we say 180o is equal to π radian.
    You can assume that π is 3.14.


    Code:
    #include <stdio.h>
    #define PI 3.14
    int main(void)
    {
    
    int a,b,c, degree;
    
    
    /* Enter the start degree, end degree, and increment */
    
    printf("Enter a b c : ");
    scanf("%d %d %d", &a, &b, &c);
    
    for (i=a;i<=b;i=i+c)
    {
    printf("degree Radian");
    printf(" %d %f", i, i*3.14/180);
    }
    system("pause");
    /* Exit program. */
    return 0;
    }
    Why have you #defined PI if you're not using it?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM