Thread: C Program

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    1

    Post C Program

    Hi All
    I tried to design a c program using if then else that will convert an input number into resistor, but it is not working. Please help me.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
      int n=152;
      int a,b,c,d,f,g,z;
      a=n/100;
      b=n/10; 
      c=n/1;
      printf("a= %d  b= %d  c= %d \n",a,b,c);
      d=n%100;
      f=n%10;
      g=n%1;
      printf("With mod ->d= %d  f= %d  g= %d\n",d,f,g);
      z=b%10; 
      printf("z=%d\n",z);
      
      if(a==0)
      {
              printf("black\n");
      }
      else if(a==1)
      {
           printf("brown\n");
      }
      else if(a==2)
      {
           printf("red\n");
      }
      else if(a==3)
      {
           printf("orange\n");  
      }
      else if(a==4)
      {
           printf("yellow\n");  
      }
      else if(a==5)
      {
           printf("green\n");  
      }
      else if(a==6)
      {
           printf("blue\n");  
      }
      else if(a==7)
      {
           printf("violet\n");  
      }
      else if(a==8)
      {
           printf("grey\n");  
      }
      else if(a==9)
      {
           printf("white\n");  
      }
      system("PAUSE");	
      return 0;
    }
    Attached Files Attached Files
    Last edited by Salem; 11-01-2015 at 02:13 PM. Reason: Inlined the code

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
      a=n/100;
      b=n/10;
      c=n/1;
      printf("a= %d  b= %d  c= %d \n",a,b,c);
    So what were you expecting to get from these?
    Three single digits 1 5 2 ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-09-2014, 02:36 PM
  2. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  3. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM