≡ Menu

If else statement in C Program

Q. Can you give me example for If else statement in C Program under Linux or TC?

A. C follows universal syntax for if..else. You can use any complier GNU Linux gcc or UNIX or old good TC.

if..else syntax

General if..else syntax is as follows:

if ( condition ) {
   expr_set1;
}
else  {
   expr_set2;
}

If given condition is TRUE, expr_set1 will get executed.
If given condition is FALSE (not TRUE), expr_set2 will get executed.

if..else example

Following example will find out large number from given input:

#include<stdio.h>
int main(){
        int x,y;
        printf("Enter value for x :");
        scanf("%d",&x);
        printf("Enter value for y :");
        scanf("%d",&y);
        if ( x > y ){
                printf("X is large number - %d\n",x);
        }
        else{
                printf("Y is large number - %d\n",y);
        }
        return 0;
}
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 291 comments… add one }

  • ferdinand v. baguingay December 10, 2008, 3:22 am
    #include
    int main(){
            int x,y;
            printf("Enter value for x :");
            scanf("%d",&x);
            printf("Enter value for y :");
            scanf("%d",&y);
            if ( x > y ){
                    printf("x is large number - %d\n",x);
            }
            else{
                    printf("y is large number - %d\n",y);
            }
            return 0;
    }
    • genji July 2, 2010, 12:05 pm

      i need more information about “if else”

      • merc velasco August 2, 2011, 10:25 am

        #include
        main()
        {
        int grade;
        char student[25],section[25];

        clrscr();
        printf(“Enter the name of a student: “);
        scanf(“%s”, &student);
        printf(“Enter the section of a student: “);
        scanf(“%s”, &section);
        printf(“Enter the grade of a student: “);
        scanf(“%d”, &grade);

        if(grade>75)
        printf(“PASSED”);
        else
        print(“FAILED”);

        getch();
        }

        • Amit February 28, 2013, 7:23 am

          friend your “scanf(“%s”, &student); ” is not correct

          the correct is “scanf(“%s”, student); ” thank you.

          • mira March 2, 2013, 7:23 am

            yes,it should be no & for character string,which means for name. only the character we must include the sign & for the scanf

            • amit March 4, 2013, 11:52 am

              yes mira i also mean the same

          • Hitesh March 31, 2014, 9:25 am

            hey amit u r wrong…………….the true statement is “scanf(“%s”,&student) Understand……

        • WAHID AKRAM November 15, 2013, 5:11 am

          how to count a repeated word in a phrase in TC (C Programming).

      • twinkle September 2, 2011, 10:14 am

        require more explanation
        and examples

      • Ratnesh February 12, 2012, 9:31 am

        if statements is a conditional statements that executes on a particular condition
        the syntax is
        if (true) /* Here true means if(12>10) ,this is true so it will execute. */
        {
        execute this code
        }
        else
        {
        else execute this code
        }

      • igki December 23, 2012, 4:06 pm

        In turbo c if clause is used in many places.An example of if statement is
        void main()
        {
        int year;
        clrscr();
        printf(“Enter the year”);
        scanf(“%d”&year);
        if(year%4==0)
        printf(It is a leap year”);
        else
        printf(“It is not a leap year”);
        }

        • naga April 30, 2014, 7:41 pm

          in the if statement instead of “if(year%4==0) “statement if i use “if(year%4) ” then what does it represents can you please explain

      • anisha October 19, 2013, 3:45 pm

        The ability to control the flow of your program, letting it make decisions on what code to execute, is valuable to the programmer. The if statement allows you to control if a program enters a section of code or not based on whether a given condition is true or false. One of the important functions of the if statement is that it allows the program to select an action based upon the user’s input. For example, by using an if statement to check a user entered password, your program can decide whether a user is allowed access to the program.

    • Devendra,sujeet jha June 9, 2011, 5:40 pm

      #include
      #include
      void main()
      {
      int x,y,large;
      clrscr();
      printf(“input any two number”);
      scanf(“%d %d”,&x,&y);
      if(x > y)
      {
      printf(“large is =%d”,x);
      }
      else
      {
      printf(“largeis =%d”,y);
      }
      getch();
      }

    • Justine July 12, 2011, 10:54 am

      What if, if I input f it would appear female alone then if m, it would male alone ?

    • affrin January 2, 2012, 10:54 am

      i need the answer for small and greatest number in 10 numbers

    • ashutosh sharma April 2, 2013, 5:00 am

      why we use return 0 in the last of program

      • arpitha.k July 8, 2014, 9:22 am

        bcz function is not returning any value

      • Ringkhang July 11, 2014, 2:01 am

        When we use int main() instead of void main(), it must be return 0. If u write void main(), none it to give return 0.

      • hari krish October 8, 2014, 11:17 am

        Because it tells the compiler to stop the program !!!

  • nazmul January 27, 2009, 9:42 am

    I need more if else program.i have simple problem.i don’t know your wbsite is active or not.next time i give a problem please solve it.

    • ankita May 5, 2010, 1:28 pm

      I need more program about if else

      • Meera. M May 25, 2010, 5:08 am

        #include
        #include
        main()
        {
        int age;
        clrscr();
        printf(“Enter the age:”);
        scanf(“%d”, &a);
        if(a<18)
        printf("can't vote");
        else
        printf("can vote");
        }

        • sreekanth October 8, 2010, 5:30 pm

          its wrong miss meera actually, wat u declared is age, and wat u using in (if statement) is a thats y its an error program

          • anisha October 19, 2013, 3:40 pm

            wrong answer

        • Devendra,sujeet jha June 9, 2011, 5:51 pm

          #include
          #include
          void main()
          {
          int age;
          clrscr();
          printf(“enter age=”);
          scanf(“%d”,&age);
          if(age>18)
          {
          printf(“can vote”);
          }
          else
          {
          printf(“can’t vote”);
          }
          getch();
          }

        • addie stha September 1, 2011, 3:52 am

          #include
          #include
          void main()
          {
          int n;
          clrscr();
          printf(“enter the number:”);
          scanf(“%d”,&n);
          if (n%2==0)
          printf(“the number is even”);
          else
          printf(“the number is odd”);
          getch;
          }

          • Chichaii January 14, 2013, 12:06 pm

            i need a example w/ no limitation..

          • ALI KASK March 16, 2015, 4:37 pm

            addie stha plz tell me wat u mean on CLRSR() and GETCH. thank you in advance

            • Marj August 19, 2015, 12:21 pm

              Hello. Im not addie, I just to answer your question If im not mistaken getch means get character means that when you run the program and you enter a number it will be saved and clrscr is to erase all number that you entered before. :)

        • ashutosh sharma April 2, 2013, 5:16 am

          there is error about voat.it gives only cannot voat

      • Bharath July 21, 2010, 9:34 am

        #include
        main();
        {
        int marks;
        scanf(“%d”,&marks);
        if(marks>35)
        printf(“Pass”);
        else
        printf(“Fail”);
        }

      • Sharad Puri May 26, 2011, 1:07 pm

        PROGRAM To find whether a given year is leap or not
        main()

        {

        int y,r1,r2;

        printf(“Enter a year”);

        scanf(“%d”,&y);

        r1=y%4;

        if (r1 = = 0)

        {

        r2=y%100;

        if(r2 = = 0)

        printf(“The given year is not a leap year”);

        else

        printf(“The given year is a leap year”);

        }

        else

        printf(“The given year is not a leap year”);

        }

        • Avinash veer July 10, 2011, 5:53 pm

          r2=y%100
          (r2!=o)

          • Avinash veer July 10, 2011, 5:58 pm

            i need aprogram whan scanf true or faise and print 100 numbers

        • rin August 3, 2011, 8:57 am

          what do u mean by “y”,”r1″,”r2″ integer there?thnks!

        • tyaiba August 25, 2011, 12:01 pm

          why we use y%4.show me answer

          • adil August 26, 2011, 2:55 pm

            y%4

            that means which value is store in y that is divided by 4
            % is a modular

            • Amit February 28, 2013, 7:37 am

              y%4 does not store the value in y the correct process is y=y%4

            • ajnabi April 30, 2013, 9:03 pm

              bro u used twice dat else statement for printing the gvn year is nt a leap year which is wrong!!
              u strtd in othr bracket within da if statement vch is nt possible!!

              • yousaf khan October 29, 2014, 4:18 pm

                how to create this program “You are required to write a program that finds the number (in the given range) which has maximum number of divisors. The program first asks the user to input two values P and Q for a range (where p < Q). After that, the program should find a number having highest number of divisors. In the end, the program should print that numbers (having highest number of divisors) along its divisor count.
                Sample Inputs:
                Enter first number (P): 1
                Enter second number (Q): 10

                Sample Output:
                6 has maximum of 4 divisors.
                "

          • waleed February 18, 2013, 12:48 pm

            we use to find leap year that is why we use y%4

        • azizur rahman October 7, 2011, 5:25 am

          the year divided by 4, get remainder zero ,is leap year.

        • collano noel rogie September 17, 2014, 3:28 am

          you sure this will run

          make it real

      • Ratnesh February 12, 2012, 9:21 am

        void main()
        {
        int num,grenum;
        grenum=10;
        printf(“Enter the number: “);
        scanf(“%d”,&num);
        if(num>gernum)
        {
        printf(“The number is Greater”);
        }
        else{
        printf(“The number is smaller”);
        }
        }

  • aldrin March 22, 2009, 1:34 pm

    can you convert this to java program?

  • saviye.saviyola April 21, 2009, 4:01 am

    I just study programming .

  • alyssa mae cruz July 6, 2009, 8:01 am

    hello all..exiting ang programming nuh?haha

    • roy March 10, 2011, 6:04 am

      yeaH..that so exiting..even though i was lil bit confused.

    • Justine July 12, 2011, 10:55 am

      depende. mnsan nkkbwisit rn. haha

  • markjasonarceo September 21, 2009, 9:45 am

    how to analyze the problem to make c program?tnx

  • carrys September 24, 2009, 3:41 am

    hi i am a n IT student. i just want to ask if you could pls give me some simple problems regarding if else , if else if else, and i/o. and also those more complicated ones. thanks.

    • rossa maljuril September 22, 2011, 4:29 am

      you just search at programming statement.then all simple of statement in if else-if else will be displayed at your answer.

  • Pooja Sree December 3, 2009, 5:15 am

    Super Example For If Statement

    • BharathSVK July 21, 2010, 9:40 am

      #include
      main()
      {
      int age;
      Printf(“Age selection for Security”);
      scanf(“%d”,&age);
      if(age<50)
      printf("Selected");
      else
      pritnf("Age excess-Sorry try Another place");
      }

    • kalpana March 7, 2012, 12:21 pm

      void main()
      {
      int i,n;
      printf(“Enter the level\n”);
      scanf(“%d”,&n);
      for(i=0;i<n;i++)
      {
      if(i%2==0)
      {
      printf("even number=%d",i);
      }
      else
      {
      printf("odd number=%d",i);
      }
      }
      }

  • allen joyce December 15, 2009, 5:55 am

    i’m excited to try this program

  • allen joyce December 15, 2009, 5:57 am

    i need to create program right now for my project …………….help me …………………hehehe using IF ELSE STATEMENT

  • allen joyce December 15, 2009, 5:58 am

    Give me another example of IF ELSE STATEMENT

    • ajwa September 25, 2011, 3:15 pm

      #include
      #include
      void main()
      {
      float mob.mt, per;
      clrscr();
      printf(“\n enter the obtained marks:”);
      scanf(“%f” , & mob);
      printf(“\n enter the total marks in exams;”);
      scanf(“%f” , & mt);
      per= mob/tm* 100;
      if(per>=40.0)
      {
      printf(“\n pass”);
      }
      else
      printf(“\n fail”);
      }
      getch();
      }

    • kalpana March 7, 2012, 12:24 pm

      void main()
      {
      int a;
      printf(“enter the a value\n”);
      scanf(“%d”,&a);
      if(a>0)
      printf(“a is positive”);
      else
      printf(“a is negative”);
      }

  • bayan December 23, 2009, 1:27 pm

    can you help me to write this home work in C programs

    *wirte the programsin C about if else
    *the program should ask the user to enter the total marks out of 100, and then display the letter grade on the screen
    *Grade Rules:
    75 and above=”A”grade
    60-74=”B”grade
    50-59=”c”grade
    40-49=”D”grade
    Below 40=”Fail”

    thanks .
    please send it to my Email bayan321@live.com

    • Kenny June 19, 2010, 12:16 pm

      Your homework is very easy just use the
      if(user>=75)
      printf(“A”);
      else if(user>=60 && user<=74)
      printf("B");

      and so on.

    • sujesha October 2, 2010, 12:20 pm

      did you manage to get the answer?
      did anyone mailed you?
      thanks
      sujesha

    • riyas October 31, 2010, 7:31 am

      void main()
      {
      float mark;
      clrscr();
      printf(“Enter the total mark out of 100”);
      scanf(“%f”,&mark);
      if(mark<==75)
      {
      print{"Student has secured A Grade ";
      }
      else
      {
      .
      .
      .
      .
      .
      .
      getch();
      }

      • myrabelle cabriana March 8, 2011, 4:59 am

        thank u..

    • sujeet jha June 10, 2011, 12:10 pm

      #include #include
      void main(){
      int i,j,k,l,m;
      clrscr();
      printf(“Enter your total marks”);
      scanf(“%d”,&i);
      if(i>=75){ printf(“Grade-A”);}
      if(i=60){printf(“Grade-B”);}
      if(i=50){printf(“Grade-C”);}
      if(i=40){printf(“Grade-D”);}
      if(i<40){printf("Fail");}
      getch();
      }

  • emxif January 22, 2010, 6:14 am

    i need some help guys
    i am making a function oriented program and i used if else statement, i know that my statement is right but there is only 1 error and it says misplaced else…..
    how can i fix that?
    pls help me….
    plss notify me on my email
    thanks

    • vince July 27, 2010, 4:36 am

      you should misplace the curly braces { }. the syntax is
      if (condition) {
      statement 1
      }
      else {
      statement 2
      }

    • ali March 3, 2011, 8:38 pm

      Hello
      make sure you use the proper braces before and after else statement.

    • JD October 8, 2011, 10:41 am

      hey else ya if ke baad semi colon ya brackat hoga isliye yeh erro aa rahi hai …………..
      for example
      else();
      if()
      so if and else use without any syntax…..
      for example
      if(condition)
      {
      statements(s)
      }
      else
      {
      statament(s)
      }
      ok byyyyyyyyyyyeeeeeeeeeeeeeeeeeeee

  • Glenn February 3, 2010, 2:26 am

    can you give more examples :-)

  • Levi February 18, 2010, 1:21 am

    Thanks I love you!!

  • mabel March 6, 2010, 2:54 pm

    pls. give me a program example of official receipt of sm using if else statement pls. we need it badly…pls…thanx

  • Darren March 9, 2010, 11:47 pm

    why can’t I place another “if statement” inside and “if statement”?

  • KAJI April 14, 2010, 11:46 pm

    using visual basic net i have to write a program using if-else statement based on the following condition the grdes of the students
    0-49 D
    50-55 C
    56-60 C+
    61-70 B
    71-75 B+
    76-85 A
    86-100 A+

    The program should repeat itself unless the user enters a negative value to terminate the program

    • venkata sai November 12, 2010, 4:05 am

      can you give me the def of if family statements

  • vishu May 26, 2010, 4:51 am

    include
    int main(){
    int x,y;
    printf(“Enter value for x :”);
    scanf(“%d”,&x);
    printf(“Enter value for y :”);
    scanf(“%d”,&y);
    if ( x > y ){
    printf(“x is large number – %d\n”,x);
    }
    else{
    printf(“y is large number – %d\n”,y);
    }
    return 0;
    }

  • Muneeb zargar June 1, 2010, 4:23 pm

    Use indentations ur prblm wl be solved

  • reyjohn June 24, 2010, 9:51 am

    PLEASE HELP ME!!!!

    Can you answer the code of this?
    The output is:

    Enter the first number:
    Enter the second number:
    Enter the third number:

    The smallest number is:
    The middle number is:
    The largest number is:

    • Noelene February 9, 2011, 11:20 am

      This is a Dev c++ software.. and if you’re using turbo c… just add –>clrscr();

      #include
      #include

      int main ()
      {
      int n1,n2,n3;
      int small, medium, large;
      clrscr();
      printf(“Enter the first number:”);
      scanf(“%d”,&n1);
      printf(“Enter the second number:”);
      scanf(“%d”,&n2);
      printf(“Enter the third number:”);
      scanf(“%d”,&n3);

      large=0;
      if (large<n1) large=n1;
      if (large<n2) large=n2;
      if (largen1) small=n1;
      if (small>n2) small=n2;
      if (small>n3) small=n3;

      medium=0;
      if (medium<n1 && medium!=large) medium=n1;
      if (medium<n2 && medium!=large) medium=n2;
      if (medium<n3 && medium!=large) medium=n3;

      printf(“The smallest number is:%d\n”,small);
      printf(“The middle number is:%d\n”,medium);
      printf(“The largest number is:%d\n”,large);
      getch();
      return 0;
      }

    • Noelene February 9, 2011, 11:23 am

      Sorry about the first one, there are some errors…

      This is a Dev c++ software.. and if you’re using turbo c… just add –>clrscr();

      #include
      #include

      int main ()
      {
      int n1,n2,n3;
      int small, medium, large;
      clrscr();
      printf(“Enter the first number:”);
      scanf(“%d”,&n1);
      printf(“Enter the second number:”);
      scanf(“%d”,&n2);
      printf(“Enter the third number:”);
      scanf(“%d”,&n3);

      large=0;
      if (large<n1) large=n1;
      if (large<n2) large=n2;
      if (largen1) small=n1;
      if (small>n2) small=n2;
      if (small>n3) small=n3;

      medium=0;
      if (medium<n1 && medium!=large) medium=n1;
      if (medium<n2 && medium!=large) medium=n2;
      if (medium<n3 && medium!=large) medium=n3;

      printf(“The smallest number is:%d\n”,small);
      printf(“The middle number is:%d\n”,medium);
      printf(“The largest number is:%d\n”,large);
      getch();
      return 0;
      }

    • Mrityunjay Agrawal May 14, 2011, 12:14 pm

      #include

      void main()
      {
      int a,b,c;
      printf(“Enter first number–>”);
      scanf(“%d”,&a);
      printf(“Enter Second number–>”);
      scanf(“%d”,&a);
      printf(“Enter Third number–>”);
      scanf(“%d”,&a);
      if(a>b && a>c)
      {
      printf(“The largest number is->%d”,a);
      if(b>c)
      {
      printf(“The middle number is –>%d”,b);
      printf(“The smallest number is— >%d”,c);
      }
      else
      {
      printf(“The middle number is–>%d”,c);
      printf(“The smallest number is – >%d”,b);
      }
      }
      else if(b>c)
      {
      printf(“Largest number is —>%d”,b);
      if(a>c)
      {
      printf(“The middle number is –>%d”,a);
      printf(“The smallest number is— >%d”,c);
      }
      else
      {
      printf(“The middle number is–>%d”,c);
      printf(“The smallest number is – >%d”,a);
      }
      }
      else
      {
      printf(“Largest number is —>%d”,c);
      if(b>a)
      {
      printf(“The middle number is –>%d”,b);
      printf(“The smallest number is— >%d”,a);
      }
      else
      {
      printf(“The middle number is–>%d”,a);
      printf(“The smallest number is – >%d”,a);
      }
      }

  • IT_Specialist June 26, 2010, 7:20 pm

    #include
    main()
    {
    int x,y,z;
    clrscr();
    printf(“Enter the first number:”);
    scanf(“%d”,&x);
    printf(“Enter the second number:”);
    scanf(“%d”,&y);
    printf(“Enter the third number:”);
    scanf(“%d”,&z);
    z=x+y+z;
    y=x+y+z;
    x=x+y+z;
    printf(“The smallest number is:%d\n”,z);
    printf(“The middle number is:%d\n”,y);
    printf(“The largest number is:%d\n”,x);
    getch();
    return 0;
    }

    • Rej Irving February 14, 2011, 5:44 am

      Can u help me on this one?I need to create a program which tells the user what color he chose using codes:

      Bl- Blue
      G-Green
      (so on and so forth)

      i did use char color;
      then
      if (color==”Bl”)
      {
      printf (“You chose BLUE”);
      }
      else
      {
      printf (“Pick another color:”);
      }
      getch ()
      }

      The thing is there is no error but the result is only “PICK ANOTHER COLOR”. It means that the condition is not read isn’t it?

      pleease help me..

  • arlyn July 5, 2010, 8:58 am

    can you make a program in this question?

    plss reply at my email address, asap!!!

    Objective:To learn how to write a C++ program using switch and do-while loop as applied to a simple airline application.

    Procedure:

    Write a program that will validate the status code so that only values from 0 to 3 will be accepted.If an invalid status code is entered, display the message “Invalid Status” and repeatedly accept a status code until a valid value is entered.Repeatedly accept passenger data prompting for “More Entries? (Y/N):” each time a set of data is entered.Terminate processing when response to this prompt is ‘N’.

    Note: for string values you need to use strcpy function to assign the value entered to a character array variable (refer to your manual).

    Name: XXXXXXXXXXXXXXXXX

    Status:XChecked-in

    Fare:9,999.99

    Specifications:

    1.The name of student and exercise no. should appear on screen.

    2.Segregate input, process, validation and output statements by introducing void functions

    3.Maintain the same display format as follows taking consideration of the error message and the “More Entries” prompt.

    Name: XXXXXXXXXXXXXXXXX

    Status :XBoarded

    Fare:9999.99

    More Entries? (Y/N):

    4.Use the switch statement to display the corresponding descriptive status.

    Statusdescription

    0On-Schedule

    1 Checked-In

    2 Boarded

    3 Arrived

  • Dyulokdyuti July 8, 2010, 1:34 am

    Thanx for help my study

  • angel August 16, 2010, 1:19 am

    Make a C program that will accept any integers from 1-12 and displays equivalent month, Example if 3 “March”.

    • anonimous August 25, 2010, 1:25 pm

      you could try using either switch case or nested if for that program

    • ... August 25, 2010, 1:31 pm

      #include
      main()
      {
      int month;
      printf(“\n Enter Number:”);
      scanf(“%d”,&month);

      switch(month){
      case 1: printf(“January”);
      break;
      case 2: printf(“Febuary”);
      break;
      case 3:… and so on up to case 12..

      default: printf(“number selected is invalid”);
      }
      }

  • jane krizia hailar August 23, 2010, 1:00 am

    i need more explanation of if-esle statement also example….

  • teoh September 5, 2010, 6:12 am

    i want to do a menu using if else,but after i try the error is occur.the error say that i using illege if else..wat is the problem that i face ,n how can i solve tis problem

  • chetan gupta September 14, 2010, 5:12 pm

    how to find square root of a number by using if else in c program?

  • Jason October 15, 2010, 11:48 am

    can you make a program that converts the value of binary to decimal, binary to-octal binary-hexa and decimal-binary, decimal-octal, decimal-hexa, and octal-decimal,octal-binary,octal-hexa, and hexa-binary,hexa-decimal,.hexa-octal;
    your prompt reply is highly appreciated. thank you in advance.!
    god bless..

  • Queen13 December 14, 2010, 9:48 am

    -SAMPLE “IF ELSE” PROGRAM-

    #include
    #include

    int main(){
    int grade;
    clrscr();
    printf(“Enter Grade:\n”);
    scanf(“%d”, &grade);

    if((grade>=80)&&(grade=75)&&(grade<=79))
    printf("Nice");

    else
    printf("Poor");

    getche();
    return 0;
    }

  • edison layco January 10, 2011, 9:51 am

    can you make a program in this output?

    output
    MODE OF PAYMENT
    [1] CASH 10% DISCOUNT
    [2] TWO-INSTALLMENT 5% INTEREST
    [3] THREE-INSTALLMENT 10% INTEREST

    ENTER YOUR TUITION FEE: 20,000
    CHOOSE MODE OF PAYMENT: 1
    THE AMOUNT OF PAYMENT:18,000

    this is the output plsss. help me

  • emi January 10, 2011, 2:17 pm

    can any one solve this:
    write a c program tht accept n integear from the user and pass it to the function that print the crossponding day 1=saturday
    2=sunday
    3=monday
    4=tuesday
    5=wednesday
    6=thursday
    7=friday

    • sonu asati October 3, 2011, 11:45 am

      #include
      #include
      void main()
      {
      int no_day;
      clrscr();
      printf(“enter the number of day \n”);
      scanf(“%d”,&no_day);
      switch(no_day)
      {
      case 2 :
      printf(“sunday”);
      break;
      case 3 :
      printf(“monday”);
      break;
      case 4 :
      printf(“tuesday”);
      break;
      case 5 :
      printf(“wednesday”);
      break;
      case 6 :
      printf(“thursday”);
      break;
      case 7 :
      printf(“friday”);
      break;
      default :
      printf(“no match “);
      }
      getch();
      }

  • ajj January 31, 2011, 10:12 am

    Can anyone tell me what will be the output of the following code.
    P.S. Ignore the errors in the statements. Just know that this is the logic.
    int a = 10;
    if (!!a)
    printf(“%d”,!a);
    else
    printf(“%d”, a)

  • ratnesh February 6, 2011, 5:43 am

    void main(){
    int i;
    switch(i){
    case 1:
    Printf(”monday”);
    case 2:
    Printf(”tuesday”);
    case 3:
    Printf(”wednesday”);
    Case 4:
    Printf(”thursday”);
    .
    .
    .
    Case 7:
    Printf(”sunday”);
    Default:
    Printf(”enter appropriate number”);
    }
    }

    • AjWa September 25, 2011, 3:27 pm

      can v also solve it by else_if too…..??

      • AjWa September 25, 2011, 3:28 pm

        ratnesh u hve nt included break statement in switch statement.. without it prog cant run..!!!

  • Roni February 7, 2011, 3:53 am

    1. Prompts the user to input a percentile mark (i.e. prints a string asking the user to input a value between 0 and 100);
    2. Reads a value from standard input and saves it in an appropriate variable (note: marks can be fractional);
    3. Prints an error message if the mark entered is less than 0 or greater than 100;
    4. If the mark is in range (i.e. between 0 and 100, inclusive) then print out the appropriate letter grade of the mark according to the following scale:
    * 90+ = A+
    * 80+ = A
    * 75+ = B+
    * 70+ = B
    * 65+ = C+
    * 60+ = C
    * 55+ = D+
    * 50+ = D
    * < 50 = F

  • wiwie69 March 3, 2011, 2:24 pm

    can you help me with this…

    ADDI, is one of the courier company that provide express service in delivering goods to customers. The tariff are based on total weight and delivery destination. Table below shows the pricelist.
    Table 1 : Weight
    Total Weight Price per kg

    1st kilogram 15.00

    The next 4kg ( 2-5kg) 13.00

    The next 20kg (6-25 kg) RM 11.00

    More than 25 kg RM 10.00

    Table 2 : Destination
    Destination Rate
    Within a state
    i. 1-25km
    i. RM 5
    ii. More than 25 km ii. RM 15
    Domestic RM 30

    For express delivery (within 1 day delivery), extra RM 25.00 is add.
    You are required to write a program that will help customer to calculate the tariff based on information given. Your program shall display:
    • Type of goods – documents or parcel
    • Quantity
    • Total weight
    • Destination
    • And delivery type – normal or express
    • Total price to be paid

  • Masha March 12, 2011, 12:59 pm

    can someone halp me with this?

    every week from monday to friday you go to class. when it is raining, you take an umbrella.
    but on the weekend,what you do depends on the weather. if it is raining, you stay indoors. otherwise, you have fun outdoors.
    write a c program to present your weekly program using if/else control statements.

  • joy March 22, 2011, 7:21 am

    please give me a code using array and function

  • renu April 2, 2011, 7:32 am

    i need more informations of c programs.

  • aklima akther April 21, 2011, 11:47 am

    can anyone help me to convert binary to octal by using for loop and bit wise operator.
    what does bit wise (n>>i &7) mean and in last for loop what does i -= 3 mean.how is it related to convert octal.can anyone please help me this,

  • anch May 25, 2011, 7:55 am

    how to compare two number using bitwise… compare means is two number is less than or greater than each other . if suppose a and b are the two number we normailly compare by using
    if(a>b)
    …..
    else
    ….
    how can i do it by bitwise … :D

  • tejas May 27, 2011, 1:22 pm

    can you help me in making calc with frem

  • Joshua May 30, 2011, 4:09 am

    Can someone help me solve this assingnment ? am submiting it soon.Thanks

    The manager, Mini Bit of the Megabyte mall wants a program to help his salespersons instantly determine the price of items purchase by their customers. To start with the manager wants a program that will be used to compute the prices of the following provisions: Fanta, Coke, Chocolate and Sprite. As a programmer you have been directed to come up with a program that will determine the item’s under consideration (eg. Fanta, coke, or…….) and ask for the price quote on the item as well as the number of that particular item you purchased. With this information the program should be able to calculate the total price someone is supposed to pay on the item.
    Start from requirement and end at design
    [15

  • sam June 1, 2011, 7:14 am

    write a c++ program to implement AND logic

    • vaishali August 14, 2015, 4:47 pm

      I want a program to display days of week like Monday Tuesday Wednesday etc when we give the year month and the date..i need it by tomorrow morning pls

  • sagal paudel June 2, 2011, 1:34 pm

    i want more in formation about the if else statement.

  • ramadhan kabange June 28, 2011, 3:50 pm

    i want to know more abt if else

    • arpit mishra August 8, 2011, 8:06 am

      #include
      int main(){
      int x,y;
      printf(“Enter value for x :”);
      scanf(“%d”,&x);
      printf(“Enter value for y :”);
      scanf(“%d”,&y);
      if ( x > y ){
      printf(“x is large number – %d\n”,x);
      }
      else{
      printf(“y is large number – %d\n”,y);
      }
      return 0;
      }

      • AjWa September 25, 2011, 3:30 pm

        if else statement is that:
        if statement provides the facility to take action provided that some given condition is true. it does not allow to take action if the given condition is false. tha if_else statement gives this opportuinty.. the syntax of if_alse statement is;

        if(condition)
        {
        statement 1;
        statement 2;
        .
        .
        .
        statement n;
        }
        else
        {
        statement 1;
        statement 2;
        .
        .
        .
        statement n;
        }

        the statement given before the else part vill be executed. if the given condition is true & in case of false statement,the statements given after the else vill be executed…..
        do u need a perfect xmple of if_else statement????

  • Justine July 12, 2011, 11:05 am

    Hi, can u help me now pls ? ahm, how to do this:
    1. When I input F it displays female
    2. When I input M it inputs male ?

  • anver va July 21, 2011, 12:49 pm

    even though compiler says “succes” .i can’t run the program it says elseif statement error

  • THONIE July 21, 2011, 3:58 pm

    plss help me with this one !!
    A salesman is paid a commission on the following basis
    Sale Value Commission
    up to $100 zero
    over $100 to $1000 2%
    over $1000 3%

    Enter the sale value and print out the commission value (use a maximum entry value of $32000)

  • jheremie rochina July 23, 2011, 5:01 am

    can u help me to get the c code of this….
    enter the first no:20
    enter the second no:30
    selection operation:+,-,/,%

  • mj calago August 12, 2011, 7:44 am

    can you give me a program for votation?? dat would also count the votes and declare who will win !!! please??? i’m begging you guys..!!!

  • joniel August 22, 2011, 3:22 am

    please give me an example using the IF statement… Please.. :)

  • Hanna August 22, 2011, 1:15 pm

    Kindly please help me with this:

    Write a program that ask the user to input item name, item unit per price and item quantity. Determine the following:

    Range(Quantity) Discount
    0-50 0%
    51-90 1%
    90-100 2%
    101-500 3%
    501-1000 5%
    1001-5000 7%
    5801-above 10%

  • Dianne August 26, 2011, 12:49 am

    Can you help me figure out this problem?

    This game is like the traditional “bato-bato pick” we Filipinos play. In this game, the user will select among “BATO”, “PAPEL”, and “GUNTING”. The computer will randomly select it’s pick. The game will be played for 5 rounds. The program will display the winner every after round and the player with the most win after 5 rounds will be declared as the winner. In case of a tie provide another round until the tie is broken.

    Kindly help me. Using C Language programming only, Using if-else statement without the use of loop or jump. Thanks

  • vaishali August 27, 2011, 5:42 am

    1 scan four values from user and find maximum number from four numbers.

    2.read any character from user and check whether that character is vowel or not . using conditional operator. (a,e,i,o,u are called vowel)

  • leecel August 29, 2011, 2:27 am

    Can you make a c program on this problem please:
    -make a c program using “if else statements” where when you enter a month(in small letters), it will display the holidays on that month!
    please, email me!

  • umesh kumar vishwakarma August 31, 2011, 1:02 pm

    /*Write a c program to accept any character and print their ASCII code.
    sol:-
    #include
    #include
    void main()
    {
    clrscr();
    char ch;
    printf(“\nEnter any character:-“);
    scanf(“%c”,&ch);
    printf(“ASCII code=%d”,ch);
    getch();
    }

  • harisha September 14, 2011, 2:04 pm

    i require a c program by using if else statement to print smallest of given four numbers

    • AjWa September 25, 2011, 3:31 pm

      if else statement is that:
      if statement provides the facility to take action provided that some given condition is true. it does not allow to take action if the given condition is false. tha if_else statement gives this opportuinty.. the syntax of if_alse statement is;

      if(condition)
      {
      statement 1;
      statement 2;
      .
      .
      .
      statement n;
      }
      else
      {
      statement 1;
      statement 2;
      .
      .
      .
      statement n;
      }

      the statement given before the else part vill be executed. if the given condition is true & in case of false statement,the statements given after the else vill be executed…..

    • Cool Gtm March 25, 2012, 8:05 am

      #include
      #include
      void main()
      {
      int a=10,b=20,c=30,d=40;
      if (a<b && a<c && a< d)
      printf("A is smallest");
      else if (b<a &&b<c &&b<d)
      printf(" b is smallest );
      else if (c <a && c<b && c <d)
      printf("c is smallest");
      else
      printf("D is smallest");
      getch()
      }

  • sneha September 15, 2011, 7:08 am

    can any one please send me a program to accept five numbers from console and then to dispaly them back on console in ascending number

  • harisha September 18, 2011, 8:31 am

    i require a c program by using if else statement to print smallest of given four numbers
    please email me

  • divya s September 19, 2011, 8:05 am

    i want more in formation about the if else statement.

  • Monica September 20, 2011, 10:02 pm

    I need help with writing a program that prompts the user to enter two dates and then indicate which date comes earlier on the calendar

    Enter first date (mm/dd/yy): 3/6/08
    Enter second date (mm/dd/yy): 5/17/07
    5/17/07 is earlier than 3/6/08

    Your help would be greatly appreciated!!!!!

    • Numan January 10, 2014, 8:08 pm

      Input 31/1/2014

      And let me know the output

  • foong September 25, 2011, 1:34 pm

    The program allows user to perform the operations of a calculator, namely addition, subtraction, multiplication and division. However, these four operations will be implemented slightly differently and they are described below.

    You must use functions to implement these arithmetic operations. The function prototypes and their descriptions are as follows:

    int add( int num1, int num 2);
    – returns the sum of num1 and num2.

    int subtract( int num1, int num2 );
    – returns the difference of num1 – num2

    int multiply( int num1, int num2 );
    – returns the product of num1 and num2. You are not allow to use the * operator. Use a loop and the add() function to implement the multiplication. Note that the product of num1 and num2 is equal to (num1 added num2 times).

    int divide( int num1, num2 );
    – returns the quotient of num1 divided by num2. If num2 is zero, it prints an error message (division by zero is invalid) and it returns the value 0.

    In addition to the functions above, the program should also have a function which prints out a nice menu that prompts the user for input. The user will always enter two numbers. The user’s input is to be interpreted in the following way.

    1. If both numbers are non-negative, it means the user wishes to perform multiplication of the two numbers.
    2. If only one number is non-negative, it means the user wishes to perform division.
    3. If both numbers are negative and the first number is bigger than the second number, then the user wishes to perform subtraction.
    4. If both numbers are negative and the first number is smaller than the second number, it means the user wishes to perform addition.
    5. If both numbers are negative and have the same value, it means the user wishes to quit the program.

    The program should allow the user to enter two numbers and then perform the corresponding task. This process should be repeated until the user enters the appropriate numbers (two negative numbers of equal value) to quit the program.

    When the user chooses to quit the program, your program should print out the following statistics. This should be done using a function. The statistics are:
    1. A count of how many times the user has performed each of the addition, subtraction, multiplication and division operations.
    2. A count of the total number of operations performed.

    help me pls….apply the use of nest if else, loops, function

  • Peter B. September 26, 2011, 3:09 pm

    Reading everything but the original post made me feel dumber. To everyone:
    1) Learn how to spell. and when and when not to capitalize
    2) Actually learn something about C before coming here.

  • sonu asati October 5, 2011, 12:32 pm

    //program for bell sound
    #include
    #include
    void main()
    {
    clrscr();
    printf(“\a wellcome wwww \ a”);
    getch();
    }

  • mutuzo ruth October 7, 2011, 7:19 am

    good and interesting

  • leah October 10, 2011, 9:30 am

    can you give me more definitions about if-else statement plsss..tnx a lot

  • Andrei de Luna October 11, 2011, 7:25 am

    can you make a program in this output?

    output
    MODE OF PAYMENT
    [1] CASH 10% DISCOUNT
    [2] TWO-INSTALLMENT 5% INTEREST
    [3] THREE-INSTALLMENT 10% INTEREST

    ENTER YOUR TUITION FEE: 20,000
    CHOOSE MODE OF PAYMENT: 1
    THE AMOUNT OF PAYMENT:18,000

    this is the output plsss. help me

    • nerissa March 14, 2013, 3:06 pm

      do you have already a code of that mode of payment

  • Maria Moosa October 12, 2011, 6:45 pm

    write a c program that will get 4 integers and will print out the maximum integer…can anyone solve this?

    • niwash October 15, 2011, 3:39 pm

      i want more information collect about if &else condition
      thanks

  • Anand panday October 15, 2011, 4:10 pm

    Pls help me. A programe which accpt three no. & if the 1st no. Is 3rd no. Then print sqare other wise multiply is by 3. If 1st no. Is >2nd no. But <3rd no. Then prnt gud question . Else print boaring question.

  • Anand panday October 15, 2011, 4:42 pm

    Ans.

    #Include
    #include
    void main()
    {
    int n1, n2, n3;
    clrscr();
    printf(“enter three no.”);
    scanf(“%d,%d,%d; &n1,n2,n3”);
    if (n1>n3)
    printf(“n1 is largest”);
    else
    printf(“n3 is largest”);
    }
    else
    {
    if (n2>n3)
    printf (“n2 is largest”);
    else
    printf (“n3 is largest”);
    }
    getch();
    }

  • nor mafuzah bt mohamad yusof October 17, 2011, 1:54 pm

    please help me..
    can you do for me this question?
    Write a program that is capable of finding the 2 largest and 2 smallest integers.
    As input, the program is to read the data from the data file TWOMM.DAT.
    This data file consists of
    line 1 int1 int2 int3…………int10
    line2 int11 int12 int13……int20

    Write the output to the screen in the form:

    The two largest values in the list are:
    … …..
    The two largest values in the list are:
    ….. …..

  • nor mafuzah bt mohamad yusof October 17, 2011, 2:03 pm

    help me please..do this answer..
    Write a program that is capable of finding the 2 largest and 2 smallest integer in a list of 20 integers.
    As input, the program is to read the data from the data file TWOMM.DAT.
    This data files consists of

    line 1 int1 int2 int3 ……………………..int10
    line 2 int11 int12 int13……………………….int20

    Write the ouput to the screen in the form:
    The two largest values in the list are:
    ….
    The two largest values in the list are:
    ……

  • fLirTty October 17, 2011, 5:58 pm

    #include
    void main()

    {
    int a,c,e,hours,wage,salary;
    printf(“enter hours\n”);
    scanf(“%d”,&a);
    salary=a*10;
    if(hours<=40)
    printf("salary=%d",salary);
    else
    printf("enter no hours");
    scanf("%d",&c);
    printf("enter the wage");
    scanf("%d",&e);
    salary=((c-40)*15)+(400);
    printf("salary=%d",salary);
    }

    • fLirTty October 17, 2011, 6:02 pm

      i havE tO makE a salary calculatOr, in which if a worker works for <=40 hours he will get 10$
      but fOr EvEry Extra hOur abOvE 40 hE wiLl wagE 1.5 timEs morE.. :/
      Outputs shOuld bE likE this: E.g.
      39 hOurs= 390 $
      40 hOurs= 400 $
      41 hOurs= 415 $
      42 hOurs= 430 $..
      can anyonE hElp.. :|

  • sumit October 24, 2011, 3:31 am

    i have some problem’s in if else statements or give me suggestion how i read about it

  • Utku October 29, 2011, 1:30 pm

    Help me plss i dont run. idont make. pls explore . . .

    1. The proper divisors of a positive integer n are those integers, excluding n itself,
    that
    divide n exactly. For example, the proper divisors of 12 are 1, 2, 3, 4 and 6.
    Write a program that inputs a positive integer and outputs its proper divisors.
    Sample run :
    Input: 8
    Output: 1 2 4
    2. A program that accepts a set of integers and displays the number of positive and negative
    numbers. The program stops when the user enters 0 for the integer value.

  • sri November 5, 2011, 8:02 am

    2. Write a program that reads the marks of a student, determine and prints the equivalent grade, based on the following:

    Marks Range Grade
    < 45 E
    45 <= Marks < 60 D
    60 <= Marks < 75 C
    75 <= Marks = 90 A

    i got do.but there got some error that i can’t find.please help me.

    #include
    void main()
    {
    int mark;
    char grade;

    printf(“Enter your mark:”);
    scanf(“%f”,&mark);

    if(mark<45)
    grade='E';

    else if(mark<=45 && mark<60)
    grade='D';

    else if (mark<=60 && mark<75)
    grade='C';

    else if(mark<=75 && mark=90);
    grade=’A’;

    printf(“Your grade is %c\n”,grade);

    }

  • sri November 5, 2011, 10:03 am

    Please give me answer for this question
    Suppose a company decides to raise the salaries of its employees according to the following table:

    employee_status years_of_service percent_raise
    Full-time Less than 5 years 4.0
    Full-time 5 years or more 5.0
    Part-time Less than 5 years 2.5
    Part-time 5 years or more 3.0

    If employee_status value is ‘F’, the employee is Full-time; if it is ‘P’, he or she is part-time. Using any selection control structure of your choice, write a program that computes the new salary of an employee given his or her employee_status, years_of_service and salary by the users.

  • hira November 8, 2011, 11:31 pm

    Write a program that prompts the user to input an integer between 0 and 25. If user enters 0 then Display A, if user enters 1 then Display B, if user enter 2 then Display C and so On…

  • Jibril November 17, 2011, 2:25 pm

    can someone solve this problem for me .
    ~ leave a comment “//” of their use and function..

    [1]van arrives
    [2]passenger arrives
    [3]passenger boards van
    [4]van leaves

    each van has the following properties: plate number, driver,passenger, limit
    let letters represent passenger vans and numbers represent passenger
    flow of van and passenger is as follows
    raymark: IF event 1 happens, then a van arrives at the terminal..
    starting with label A
    there can only be one passenger van at the terminal
    at a time
    hence
    if event 1 happens while there is still a van at the terminal, . message saying “terminal is full”
    should be displayed. the next van that arrives at the terminal should be labeled as b and so on

    if event 2 happens, a passenger arrives at the terminal, starting with label 1, if there is a van at the terminal, then the passenger boards the van automatically(event3). otherwise, the passenger waits in a queue. once a van arrives the passenger un the queue will automatically load the van.

    a van automatically leaves the terminal(event4) if the number of a passenger who have boarded is equal to the passenger limit of the van
    the foolowing information mus be displayed at all times: current van label and passenger list.

    you are to write an iterative, menu driven JAVA APPLICATION that simulates the van at ATC

    the following implementation details are req: functions use of control structures – selection and control and use of variable

    ( free to organize your menu choices as long as the feature described above . )

    Your help would be greatly appreciated!!!!!
    send to my email..

  • Jibril November 17, 2011, 2:27 pm

    follow up ! using DEV c++ compiler …

  • jia November 28, 2011, 5:17 am

    Write a program in which user enters the integer value and your program returns its binary equivalent. can any body help me with it?

  • janani December 2, 2011, 4:09 am

    can u just tell me, wat condition shuld be placed inside for loop

    if( )
    {
    printf(“abcd”);
    else
    printf(“acdb”)
    }

    it should give output as

    abcd
    acdb

    or

    acdb
    abcd

    pls can u just tell me wat condition should be given inside if loop..

    • DeeP_HackeRR January 24, 2013, 6:23 pm

      Dude it will print “abcd” when condition is true otherwise when condition is false it will put “acdb”…to make neat and easy code using ‘For’ loop try to give “TRUE” condition.like wrote below:
      if (num>0)
      printf(“You have Entered positive number”);
      else
      printf(“You have Entered nagative number”);

    • sanat June 12, 2013, 12:56 pm

      after condition use ;

  • Patricia December 8, 2011, 12:33 pm

    help me please. I need to make a program entering someone’s birthday and the current date today and it will identify your age. How??

  • prabhat December 8, 2011, 1:43 pm

    thankz a lot

  • Joseph December 10, 2011, 3:22 am

    /*Create a C++ Program that will input
    two (2) values and will output its:
    -> sum -> exponent product
    -> difference -> square root of the first value
    -> product -> square root of the second value
    -> quotient -> remainder/modulo quotient
    -> integer quotient */

    #include
    #include

    using namespace std;

    int main()
    {

    double Number1,Number2,IntegerQoutient;
    double Sum,Difference,Product,Qoutient;
    double ExponentProduct,squareroot1,squareroot2,remainder;

    cout <<"This is a calculator" << endl;

    cout <> Number1;
    cout <> Number2;

    Sum=Number1+Number2;
    Difference=Number1 – Number2;
    Product=Number1 * Number2;
    Qoutient=Number1 / Number2;
    IntegerQoutient=Number1/ Number2;
    ExponentProduct=pow(Number1,Number2);
    squareroot1=sqrt(Number1);
    squareroot2=sqrt(Number2);
    remainder=fmod(Number1,Number2);

    cout <<"OPERATION:" << endl;
    cout < Press 1″ << endl;
    cout < Press 2″ << endl;
    cout < Press 3″ << endl;
    cout < Press 4″ << endl;
    cout < Press 5″ << endl;
    cout < Press 6″ << endl;
    cout < Press 7″ << endl;
    cout < Press 8″ << endl;
    cout < Press 9″ << endl;
    int n;

    cout << "Please choose any from the option above " <> n;

    if (n==1)
    cout <<"Youve chosen Addition, the answer is: "<< Sum << endl;
    else if (n==2)
    cout <<"Youve chosen Subtraction, the answer is: "<< Difference << endl;
    else if (n==3)
    cout <<"Youve chosen Multiplication, the answer is: "<< Product << endl;
    else if (n==4)
    cout <<"Youve chosen Division, the answer is: "<< Qoutient << endl;
    else if (n==5)
    cout <<"Youve chosen IntegerQoutient, the answer is: "<< IntegerQoutient << endl;
    else if (n==6)
    cout <<"Youve chosen ExponentProduct, the answer is: "<< ExponentProduct << endl;
    else if (n==7)
    cout <<"Youve chosen Squareroot of 1st no, the answer is: " << squareroot1 << endl;
    else if (n==8)
    cout <<"Youve chosen Squareroot of 1st no, the answer is:" << squareroot2 << endl;
    else if (n==9)
    cout <<"Youve chosen Remainder, the answer is:" << remainder <9

  • Joseph December 10, 2011, 3:24 am

    /*Create a C++ Program that will input
    two (2) values and will output its:
    -> sum -> exponent product
    -> difference -> square root of the first value
    -> product -> square root of the second value
    -> quotient -> remainder/modulo quotient
    -> integer quotient */
    ——— my answer
    #include
    #include

    using namespace std;

    int main()
    {

    double Number1,Number2,IntegerQoutient;
    double Sum,Difference,Product,Qoutient;
    double ExponentProduct,squareroot1,squareroot2,remainder;

    cout <<"This is a calculator" << endl;

    cout <> Number1;
    cout <> Number2;

    Sum=Number1+Number2;
    Difference=Number1 – Number2;
    Product=Number1 * Number2;
    Qoutient=Number1 / Number2;
    IntegerQoutient=Number1/ Number2;
    ExponentProduct=pow(Number1,Number2);
    squareroot1=sqrt(Number1);
    squareroot2=sqrt(Number2);
    remainder=fmod(Number1,Number2);

    cout <<"OPERATION:" << endl;
    cout < Press 1″ << endl;
    cout < Press 2″ << endl;
    cout < Press 3″ << endl;
    cout < Press 4″ << endl;
    cout < Press 5″ << endl;
    cout < Press 6″ << endl;
    cout < Press 7″ << endl;
    cout < Press 8″ << endl;
    cout < Press 9″ << endl;
    int n;

    cout << "Please choose any from the option above " <> n;

    if (n==1)
    cout <<"Youve chosen Addition, the answer is: "<< Sum << endl;
    else if (n==2)
    cout <<"Youve chosen Subtraction, the answer is: "<< Difference << endl;
    else if (n==3)
    cout <<"Youve chosen Multiplication, the answer is: "<< Product << endl;
    else if (n==4)
    cout <<"Youve chosen Division, the answer is: "<< Qoutient << endl;
    else if (n==5)
    cout <<"Youve chosen IntegerQoutient, the answer is: "<< IntegerQoutient << endl;
    else if (n==6)
    cout <<"Youve chosen ExponentProduct, the answer is: "<< ExponentProduct << endl;
    else if (n==7)
    cout <<"Youve chosen Squareroot of 1st no, the answer is: " << squareroot1 << endl;
    else if (n==8)
    cout <<"Youve chosen Squareroot of 1st no, the answer is:" << squareroot2 << endl;
    else if (n==9)
    cout <<"Youve chosen Remainder, the answer is:" << remainder << endl;

    return 0;
    }

  • Md.Akbar December 13, 2011, 1:51 pm

    #include
    #include
    main()
    {
    int x,y;
    clrscr();
    printf(“Enter a value for x and y:”);
    scanf(“%d%d”,&x,&y);
    if(x>y)
    printf(“X is greater”);
    else
    printf(“Y is greater”);
    getch();
    }

    • pradeep kumar October 18, 2012, 1:15 pm

      good

  • Hak December 22, 2011, 1:22 pm

    when have exersice about time ?what we do in if else?can u example

  • student December 24, 2011, 12:37 pm

    Thankyou for post!! If- else statement examples still not enough.
    Im not being able to find out what exactly the error is here:
    #include
    void main()
    {
    int numsweet;
    double cost;
    printf(“How many icecream do you want : “);
    scanf(“%f, &numsweet”);
    cost = 12.10 * numsweet;
    if (numsweet > 1000)
    {
    printf(“The store does not have that much icecream in stock!”);
    }
    else
    {
    printf(“You have to pay $%f to the cashier!\n Thankyou!\n”, cost);
    }
    }

    It gives a warning saying says “Possible use of numsweet before definition in funtion main. Plz help! any advice is welcomed.

    • muru October 5, 2012, 9:40 am

      scanf(“%f, &numsweet”);
      change this to :
      scanf(“%f”, &numsweet);

    • Brendon October 13, 2012, 9:14 am

      Your header file declaration is incomplete #include 2.scanf(“%f”,&numsweet); here you didn’t close the conversion or format string with quotes””.

    • Deepak Jain November 2, 2012, 5:56 am

      While reading integer use %d & not %f.
      %f is used to read a float value not a integer

  • SATYARANJAN DAS December 24, 2011, 1:49 pm

    #include
    void main()
    {
    int n,rem;
    clrscr();
    printf(“enter the number”);
    scanf(“%d”,&n);
    rem=n%2
    if(rem==0)
    printf(“the number is even”);
    else
    printf(“the number is odd”);
    getch();
    }

  • pop December 24, 2011, 1:56 pm

    #include
    void main()
    {
    int a=10;
    if(x==10)
    {
    printf(“pop”);
    printf(“rock”);
    }
    else
    printf(“song”);
    printf(“romance”);
    }
    o/p:-pop rock romance

  • Mohamad Mostafa January 8, 2012, 1:52 am

    i need you help guys about something, i am trying to use “if and else” commands but it’s not working at all, can someone tell me what i did wrong ?!!!

    #include
    main()
    {
    char name[4] = {”};
    char namem[5] = {”};

    printf(“What is your name ?!\n”);
    scanf(“%s”, &name);

    if(“name==Mark”)
    {
    printf(“Right, Your name is %s\n\n”, &name);
    }

    else {
    printf(“No, your name is Mark”, &namem);
    }

    system(“pause”);
    }

    • khushi October 18, 2012, 12:01 pm

      #include //link section
      #include
      void main()
      {
      char name[4]; //local variable declare string type
      char namem[5]=”ANIL”; //declare & initialized string
      clrscr();
      printf(“What is your name ?”);
      scanf(“%s”, name); // input any string in run time

      if(name==”Mark”) // check condition
      {
      printf(“Right, Your name is: %s”,name);
      }

      else
      {
      printf(“No, your name is Mark %s”, namem);
      }
      getch();
      }

    • rex January 5, 2015, 12:20 am

      can you make a program in this output?

      output
      MODE OF PAYMENT
      [1] CASH 10% DISCOUNT
      [2] TWO-INSTALLMENT 5% INTEREST
      [3] THREE-INSTALLMENT 10% INTEREST

      ENTER YOUR TUITION FEE: 20,000
      CHOOSE MODE OF PAYMENT: 1
      THE AMOUNT OF PAYMENT:18,000

      this is the output plsss. help me

  • hansel January 22, 2012, 3:16 am

    The number 153 has interesting property, it equals to the sum of the cubes of its digit, that is 13+53+33=1+125+27=153. Construct a C Program that reads in a positive three integer number and determine if the number satisfy the property or not. Accordingly, display the number with a message “SATISFY THE PROPERTY” or “DOES NOT SATISFY THE PROPERTY”.

    • rajeeva February 26, 2012, 3:35 pm

      #include
      int main()
      {
      int A,a,B,b,num,T;

      printf(“\t Please Enter an Integer you need to check the properties :”);
      scanf(“%d”,&num);

      A=num%10;
      a=num/10;
      B=a%10;
      b=a/10;
      //This is to check the values, in case of confusion//
      printf(“A=%d a=%d B=%d b=%d \n”,A,a,B,b);

      A=A*A*A;
      B=B*B*B;
      b=b*b*b;
      //This is to check the values, in case of confusion//
      printf(“A=%d B=%d b=%d \n”,A,B,b);
      T=A+B=b;
      if(T==num)
      {
      printf(“\t SATISFY THE PROPERTY/n”);
      }
      else
      {
      printf(“\t DOES NOT SATISFY THE PROPERTY /n”);
      }
      return 0;
      }

      Since this is regarding if-else statement you may use this method,but can also reduce the steps by using a for or do-while loop,=)

      • rosen September 12, 2012, 4:57 pm

        @hansel
        this number 153 is one of the armstrong numbers..
        an armstrong number is a number whose sum of the cube of the digits is same as that of the number..

        #include
        #include
        void main()
        {
        int r,c1,c2,c3,n,t,num;
        clrscr();
        printf(“\n please enter the 3 digit no.”);
        scanf(“%d”,&n);
        t=n;
        //calculates the cube of last digit
        r=n%10;
        n=n/10;
        c1=r*r*r;
        //calculates the cube of middle digit
        r=n%10;
        n=n/10;
        c2=r*r*r;
        //calculates the cube of first digit
        r=n%10;
        n=n/10;
        c3=r*r*r;
        //sums up the cubes
        num=c1+c2+c3;
        //checking
        if(num==t)
        {
        printf(“\n%d Satisfies the property”,t);
        }
        else
        {
        printf(“\n%d doesnot Satisfies the property”,t);
        }
        getch();
        }

  • hansel January 22, 2012, 3:17 am

    Plss. .help me about this problem. . . .

  • sangeetha January 25, 2012, 2:14 pm

    i want the program to fing greatest among 4 numbers using nested if else ladder

  • Anna January 30, 2012, 12:01 pm

    Please help me guys!!!!!!!!!!!!!
    I need a program for the sales and inventory system…….ASAP!!!!!!!!!!!
    if ever who have a knowledge about the said system please email me at my yahoo account….. annarah_aquipan@yahoo.com
    “May God will pay back you for your kindness”……..
    Thank you so much!!!!!!!!!!!

  • enkeli February 4, 2012, 2:15 pm

    pls help me

    pls create a program that will accept 5 integers and display the lowest integer

    pls use nested if for c++/turbo c

    thanks..

  • enkeli February 4, 2012, 2:19 pm

    pls create a program that will accept 5 integers and display the highest and the lowest number

    any conditional statement in c++/turbo c

    thanks..

  • skret February 9, 2012, 5:32 am

    can

  • skret February 9, 2012, 5:33 am

    some one please help me on my task, i need to write a program that can read 10 integer and then display the:

    >biggest number
    >smallest number
    >total
    >average

  • Reccalyn Castillo February 9, 2012, 10:56 am

    –>> i badly need the answer regarding this program, can you help me:))

    Write a program that complete the users prompt a services of numbers the program must be determine the odd and even number.. prompt by the users ; also sum the odd and even numbers.

  • shiva February 9, 2012, 11:17 am

    Nice to see this site.
    am learning c language from this cyberciti.biz web site. its really good to learn c for freshers.

  • hassan February 10, 2012, 4:28 am

    write a program that inputs movie and displays his movie according ti following character ;
    s sorrow movie
    r romentic movie
    a action movie
    s scientific movie
    f funny movie

    • Cool Gtm March 25, 2012, 8:53 am

      //trying first check this program n plz send comment in cool_gtm2005@yahoo.com
      void main()
      {
      char m1[20],m2[20],m3[20],m4[20],m5[20];
      char ch;
      printf(“Enter the five different movies\n\n”);
      scanf(“1 %2s \n %2s \n %2s \n %2s \n %2s”, &m1,&m2,&m3, &m4, &m5);
      clrscr();
      printf(“enter the choice( S,R,A,s,F) TO GET MOVIES”);
      scanf(“%c”,&ch);
      if(ch==’S’)
      printf( ” ur selection is %s”,m1);
      eise if (ch==’R’)
      printf(“ur selection is %s”,m2);
      else if ( ch==’A’)
      printf(“ur selection is %s”,m3);
      else if (ch==’s’)
      printf(” ur selection is %s”,m4);
      else
      printf(” ur selection is %s”,m5)
      getch();
      }

      • arnel March 22, 2013, 3:02 pm

        what does ch means? i dk, sorry explain.

  • swapna yadav February 17, 2012, 7:55 am

    can anyone say me y do v use == instead =

    • arnel March 22, 2013, 3:02 pm

      == is use for if conditions while = is use for assigning a value. for example, if(a==1) and int a=1.

  • Ahsin Khan February 21, 2012, 6:17 am

    I want to make a program to find out largest and smallest numbers out of 5 numbers using only 10 if statements and 7 printf statements……is there any one who can solve it…please let make it solve quickly its assignment……!!!!

    • Cool Gtm March 25, 2012, 9:06 am

      // im trying coo gtm less than 10 if state
      void main()
      {
      int num1,num2,num3,num4,num5,great;
      if (num1>num2 && num>num3 && num1>num4 && num1>num5)
      great=num1;
      else if (num2>num1 && num2 >num3 && num2 >num4 && num2> num5)
      great=num2;
      else if (num3>num1 && num3 >num2 && num3 >num4 && num3 > num5)
      great =num3;
      else if (num4>num1 && num4 >num2 && num4 >num3 && num4>num5)
      great=num4;
      else
      grate=num5;
      /* same opposite to smallest number*/
      printf( “the greatest number is %d”, great);
      getch();
      }

  • mary faith February 24, 2012, 3:46 am

    i want to make a program that will ask the user, how much will be the cost in playing in the computer shop per minute. the program will calculate the cost based on the given formula.

    1.) 1 peso every 4mins.
    cost * mins = total payment

    2.) cost * sec. = total payment
    sec. =.25

  • sandhya March 13, 2012, 3:32 pm

    hi!! i need the answer for this program please. :):)
    Write A Program To Accept The Marks Of Five Subjects And Find The Total And Percentage.
    Description :-
    If Value Of Any Of Five Subjects Is Negative Or Zero Or 100 An Appropriate Error Is To Be Displayed On The Screen And Program Should Terminate.

  • Reshma Rajeev April 1, 2012, 6:58 am

    If(“condition”)
    printf(“Hello”);
    else
    printf(“World”);

    What should be the “condition” if the output is “HelloWorld”.

    • shadik August 9, 2012, 7:33 pm

      condition means….num==num2 or num!=num2 like this.but you just use
      if(condition) but you didn’t give any condition.

  • anum shakir April 24, 2012, 2:47 pm

    hi i need heip from u in this program and my question is
    write a program that perform all basic operation of calculator.?
    these re options
    1) add, sub. multiply, divide
    2) using oject and class of iostream and ostream
    # long as data type .
    plz send me thiz program tomorrow itz my assignment and i ll be very grate ful to u for thiz favour thnkz

  • Ly po May 12, 2012, 11:53 am

    I want to print like This In C++ and C
    ######
    #####
    ####
    ###
    ##
    #
    Thanks

    • sitesh September 22, 2012, 4:08 am

      #include
      void main()
      {
      char title[]=”SUBHAS CHANDRA BOSE”;
      for(int i=0; title[i];i++)
      cout<<"\n"<<(title+i);
      }

    • Chetna January 28, 2013, 4:16 am

      for(i=8;i>0;i–)
      {
      printf(“\n #”);
      }

  • Rajat May 14, 2012, 12:14 pm

    please, help me task ,
    write a c program input any number b/w 1 to 12 and print month name according to input number.(using if else statement)

    • Chetna January 28, 2013, 4:22 am

      if(m==1)
      {
      printf(“\n January”);
      }
      else if(m==2)
      {
      printf(“”\n February);
      }
      else if(m==3)
      {
      printf(“”\n March);
      }
      else if(m==4)
      {
      printf(“”\n April);
      }
      else if(m==5)
      {
      printf(“”\n May);
      }
      else if(m==6)
      {
      printf(“”\n June);
      }
      else if(m==7)
      {
      printf(“”\n Julye);
      }
      else if(m==8)
      {
      printf(“”\n Ogust);
      }
      else if(m==9)
      {
      printf(“”\n September);
      }
      else if(m==10)
      {
      printf(“”\n Octomber);
      }
      else if(m==11)
      {
      printf(“”\n November);
      }
      else if(m==12)
      {
      printf(“”\n December);
      }
      else
      {
      printf(“”\n Invalid selection);
      }

  • darmie May 19, 2012, 8:40 am

    pls help write a program in c-language. the integral of (2t^2 +3t +1) the limit is from 0 to 4.using the trapezoidal rule

  • Hozefa May 26, 2012, 6:55 am

    include
    main()
    {
    int m;
    cout<>m;
    if(m==0)cout<<"Jan";
    else if(m==o)cout<<"Feb";
    else if(m==o)cout<<"Mar";
    else if(m==o)cout<<"Apr";
    else if(m==o)cout<<"May";
    else if(m==o)cout<<"June";
    else if(m==o)cout<<"July";
    else if(m==o)cout<<"Aug";
    else if(m==o)cout<<"Sept";
    else if(m==o)cout<<"Oct";
    else if(m==o)cout<<"Nov";
    else if(m==o)cout<<"Dec";
    else cout<<"Wrong entry";
    getch();}

    • Chetna January 28, 2013, 4:24 am

      include
      main()
      {
      int m;
      coutm;
      if(m==1)cout<<"Jan";
      else if(m==2)cout<<"Feb";
      else if(m==3)cout<<"Mar";
      else if(m==4)cout<<"Apr";
      else if(m==5)cout<<"May";
      else if(m==6)cout<<"June";
      else if(m==7)cout<<"July";
      else if(m==8)cout<<"Aug";
      else if(m==9)cout<<"Sept";
      else if(m==10)cout<<"Oct";
      else if(m==11)cout<<"Nov";
      else if(m==12)cout<<"Dec";
      else cout<<"Wrong entry";
      getch();}

  • dorothy June 12, 2012, 6:26 am

    so nice answers are provide and sharing

  • Sandeep Chaurasia August 7, 2012, 4:46 pm

    void main()
    {
    int i,j;
    clrscr();
    for(i=1;i=i;j–)
    printf(“#”,j);
    printf(“\n”);
    }
    getch();
    }

  • Poorva August 22, 2012, 7:19 pm

    #include
    #include
    void main()
    {
    int x;
    printf(“enter any number between 1 to 12”);
    scanf(“%d”,&x);
    if(x==1)
    {
    printf(“month is jan. %d\n”,x);
    }
    else if(x==2)
    {
    printf(“month is feb%d\n”,x);
    }
    else if(x==3)
    {
    printf(“month is march .%d\n”,x);
    }
    else if(x==4)
    {
    printf(“month is april %d /n”,x);
    }
    else if……………….
    …………………………………….
    ………………..
    ………………………
    …………………………….
    else(x==12)
    {
    printf(“month is december %d\n”);
    }
    getch();
    }

  • atal September 29, 2012, 6:08 pm

    how to use if else statment to find out the that given integer is prime no or not

  • pravin parse October 2, 2012, 7:38 am

    write a c programme to calculate first class, second class, pass class, of student where marks by supplied by user/*………………plz give me ans fast…………..*/

  • Tanvir Hossain October 17, 2012, 6:28 pm

    you have to work with three temperature types: Celsius, Fahrenheit and Kelvin. What we are going to do here, people would come to you to ask to convert temperature. They come with three inputs, the temperature which they want to convert, the type of the temperature and the intended type to convert it. As we are dealing with three types of temperature, we represent them 0, 1 and 2 (Celsius = 0, Fahrenheit = 1 and Kelvin = 2). The temperature is a number (floating point). The output is the temperature in the intended type.

  • fateh October 26, 2012, 6:47 am

    how to put if else inside if else?

    #include
    void calculation();
    int main(void)
    {
    int type,no_resistor,resistor1,resistor2,resistor3,voltage,totalr,current;
    printf(“Circuit Calculator V1.0\n”);
    printf(“Structured programming & interfacing\n”);
    printf(“By: Muhammad Al-fateh\n”);
    printf(“Date: 1 NOV 2012\n”);
    printf(“Purpose:This programme will ask user to enter elements of circuit and calculate the total resistance & current value\n\n”);
    printf(“———————————————–\n”);
    printf(“Please choose type of circuit:\n”);
    printf(“1.Series Circuit\n”);
    printf(“2.Parallel Circuit\n”);
    scanf(“%d”,&type);
    if (type == 1)
    {
    printf(“You have choosen Series circuit.\n”);
    printf(“Enter number of resistor (2 or 3 resistor only):”);
    scanf(“%d”,&no_resistor);
    printf(“This is how the circuit look like\n\n”);
    }

    if (no_resistor == 2)
    {
    printf(” +—–===—-===—–+\n”);
    printf(” | R1 R2 |\n”);
    printf(“(v) |\n”);
    printf(” +——————–+\n”);
    calculation();
    }
    else if (no_resistor == 3)
    {
    printf(” +—–===—-===—–+\n”);
    printf(” | R1 R2 |\n”);
    printf(“(v) |\n”);
    printf(” +—-===————-+\n”);
    printf(” R3 \n”);
    calculation();
    }
    else
    {
    printf(“Choose between 2 or 3 ONLY\n”);
    }

    else if (type ==2)
    {
    printf(“You have choosen Parallel circuit.\n”);
    printf(“Enter number of resistor (2 or 3 resistor only):\n”);
    scanf(“%d”,&no_resistor);
    printf(“This is how the circuit look like\n\n”);
    }
    if (no_resistor == 2)
    {
    printf(” +——===—–+\n”);
    printf(” | R1 |\n”);
    printf(” +——===—–+\n”);
    printf(” | R2 |\n”);
    printf(” +——(V)—–+\n”);
    calculation();
    }
    else if (no_resistor == 3)
    {
    printf(” +——===—–+\n”);
    printf(” | R1 |\n”);
    printf(” +——===—–+\n”);
    printf(” | R2 |\n”);
    printf(” +——===—–+\n”);
    printf(” | R3 |\n”);
    printf(” +——(V)—–+\n”);
    calculation();
    }
    else
    {
    printf(“Choose between 2 or 3 ONLY”);
    }
    else
    {
    printf(“Choose between no 1 or no 2 (tips: enter digit only)”);
    }
    return(0);
    }
    void calculation()
    {
    int type,no_resistor,r1,r2,r3,voltage,totalr,current; //r1 = resistor 1 and so on..
    printf(“This program will now calculate the total voltage and current\n”);
    printf(“Please enter voltage value (for battery):”);
    scanf(“%d”,voltage);
    printf(“Please enter resistor value based on diagram given:”);

    if ( type == 1 && no_resistor == 2)
    {
    printf(“Enter value R1 and R2 ( put space between answers)”);
    scanf(“%d %d”,&r1,&r2);
    totalr = r1+ r2;
    current=voltage/totalr;
    printf(“Total resistance = %d and current = %d”,totalr,current);
    }
    else if ( type == 1 && no_resistor == 3)
    {
    printf(“Enter value R1 ,R2 and R3( put space between answers)”);
    scanf(“%d %d %d”,&r1,&r2,&r3);
    totalr = r1+ r2;
    current=voltage/totalr;
    printf(“Total resistance = %d and current = %d”,totalr,current);
    }
    else if (type == 2 && no_resistor == 2)
    {
    printf(“Enter value R1 and R2 ( put space between answers)”);
    scanf(“%d %d”,&r1,&r2);
    totalr = 1/((1/r1)+ (1/r2));
    current=voltage/totalr;
    printf(“Total resistance = %d and current = %d”,totalr,current);
    }
    else if ( type == 2 && no_resistor == 3)
    {
    printf(“Enter value R1 ,R2 and R3( put space between answers)”);
    scanf(“%d %d %d”,&r1,&r2,&r3);
    totalr = 1/((1/r1)+ (1/r2)+(1/r3));
    current=voltage/totalr;
    printf(“Total resistance = %d and current = %d”,totalr,current);
    }
    else
    {
    printf(“null”);
    }
    }

  • Dilip kumar December 18, 2012, 9:23 am

    #include
    #include
    main ()
    {
    int x,y;
    scrclr();
    printf(“Enter value for x :”);
    scanf(“%d”,&x);
    printf(“Enter value for y :”);
    scanf(“%d”,&y);
    if ( x>y)
    {
    printf(“X is less-than: %d\n”,x);
    }
    else{
    printf(“Y is greater-than: %d\n”,y);
    }
    getch();
    }

  • santosh January 9, 2013, 7:01 am

    i need while loop examples

    • vidhya January 15, 2013, 3:30 am

      #include
      main()
      {
      int i=0;
      while(i<10)
      {
      printf("gud morning");
      }
      getch();
      }

  • vidhya January 15, 2013, 3:01 am

    hai, i want a simple program about for loop. may u pls.thanks

  • romeje January 15, 2013, 12:34 pm

    the xyz telegram company charges 18.50 for telegram that do not exceed 12 words and 1.50 pesos for every succeeding word.construct a C program that accepts the number of words in a telegram compute and display the charges.

  • Yogesh January 16, 2013, 2:58 am

    Can anyone clarify on me, on below statement,

    if (++time>59)
    {
    statement1;
    }

  • cj January 23, 2013, 2:33 pm

    somebody help me plzz .. so important :D

    the new telephone company has the follwing rate structure for long distance calls:

    a. any call started after 7:00PM (1900hrs) but before 8:00 (0800 hours) is discounted 30%
    b. any call stared after 8:00 am (0800 hours) but before 7:00 (1900 hours) is charged full.
    c. all calls are subjected to 8% tax
    d. the regular rate for a call is P15.00 per minute.
    e. Any call longer than 60 minutes receives a 20% discount on its cost (after any other discount is subtracted but beofre tax is added)

    Instructions:
    1. Write a c program that takes the start time for a call based on a 24-hour clock and the lenght of the call in minutes. the gross cost (before any discounts or tax) should be printed followed by the net cost (after discounts is deducted and tax added).
    2. Design a graphical user interface or GUI that fits to the given problem.
    3. The program will accept multiple user.

  • vidhya January 25, 2013, 11:57 am

    hai, i want to know about while loop

  • navya January 26, 2013, 7:35 am

    give the syntax of simple if statement in c

  • soumen dofadar January 26, 2013, 5:30 pm

    good…but not enough to understand clearly…..

  • Eva mae January 30, 2013, 2:33 am

    guys!! will you help me to create a program that have a switch statement,do while, and if else.. this is can be see in a one program only..!

  • Siddarth February 5, 2013, 2:10 pm

    #include
    int main()
    {
    int x,y;
    printf(“enter value for x=”);
    scanf(“%d”,&x);
    printf(“enter value for y=”);
    if(x>y){
    printf(“x is the greater number=%d\n”,x);
    }
    else{
    printf(“y is the greater number\n”,y);
    }
    return 0;
    }

  • kartikpareek February 10, 2013, 8:26 am

    plz give answer -wap to input number continuslt but only positive number will display input 0 for stop program?

  • krishan kant azad February 24, 2013, 3:27 pm

    #include
    #include
    void main()
    {
    int a;
    clrscr();
    printf(“enter the any value”);
    scanf(“%d”,&a);
    if(a==5)
    printf(“A is a greater the”);
    else
    printf(B is a less then);
    getch();
    }

  • Sheukh March 11, 2013, 12:54 pm

    //* hi friends i have a problem with the following program.actualy i used turbo c compiler under dosbox 0.74v when i compile this program then it shows none error.when i run this program then it runs properly but i cant get desired o/p.
    this program is to define wether the driver is insured or not.conditions for insurance are as
    1) if driver is married – then driver is insured.
    2) if driver is unmarried,male and age more than 30 – then driver is insured.
    3) if driver is unmarried,female and age more than 25 – then driver is insured.
    when i enter age-22,sex-f,and marrital status-u
    (i.e.age=22/sex=female/marrital status=unmarried)
    then i get o/p that driver is insured.
    so kindly help me.
    #include
    void main()
    {
    clrscr();
    char ms,sex;
    int age;
    printf(“enter age,sex & marrital status\n”);
    scanf(“%d%c%c”,&age,&sex,&ms);
    if(ms==’m’)
    printf(“driver is insured\n”);
    else
    {
    if(sex==’m’)
    {
    if(age>30)
    printf(“driver is insured\n”)
    else
    printf(“driver is not insured\n”);
    }
    else
    {
    if(age>25)
    printf(“driver is insured\n”);
    else
    printf(“driver is not insured\n”);
    }
    }
    getch();
    }

  • mike March 12, 2013, 12:51 am

    Prompt the user for a day number then print the name of the day, where 1 = Sunday, 2 = Monday, etc. If the user enters a number other than 1 through 7, print an error message.

    Use If-then/else statement and then do the same for switch statements

  • muhammd asim ismaila March 15, 2013, 3:36 am

    need a little more simplicity and explanation

  • neeraj March 21, 2013, 4:50 pm

    write a pgm using logical operation to find out that a person has insurence policy or not
    1) if married
    2)if unmaried – gender-male
    age more than 30 years
    gender- female
    age more than 23 years
    can smone tell me completely.

  • manoo March 25, 2013, 8:05 pm

    show the solution at the vedio store new releases rent for 3.00 a night oldies rent 2.00 your sales clerk will enter 1 for new release 2 for oldies to be stored in the variable type OR write the statement s that would increment the appropriate counter variable keeping track of the number of new releases and oldies rented and add the appropriate amount to the variable keeping track of the current sale.

  • manoo March 25, 2013, 8:07 pm

    i wana need a help for solving this solution plz help me

  • sohaimey March 26, 2013, 11:43 am

    I need loop (while, do while, do) in C program

  • newbie March 30, 2013, 4:50 am

    sir .. can you help me.. plss..
    using do/while loop write a program that computes and display the sum of all even positive input numbers. the program terminates if it reads a negative number..

    sample input/ouput dialogue:
    enter a number:1
    enter a number:2
    enter a number:3
    enter a number:4
    enter a number:-4

    the sum of all even number(s) is:6

    now na po.. ^_^

    • Kevin July 17, 2013, 6:16 am

      sum = 1+2+3+4+-4;

  • Marc April 18, 2013, 10:27 am

    Need help please. Assignment Please answer it. Thank you so much :)

    write a program that computes the grade of a student using the formula:
    grade=40% major exam + 30% ave of 2 long exams + 30% of a short quizzes.
    Display the average of two long exams, average of 3 short quizzes and the grade of the student.display also a message whether the student passed of failed passing is 75%

  • Roy May 14, 2013, 9:26 am

    Prompt the users to enter the subject name and traverse the list of subjects and if the entered subject is in list, display the name of the subjects (English, Math, Science. French). Using only if/switch statements

  • abdi May 17, 2013, 5:15 am

    hy guys i did this program my assigment so i wanna added like when you ask you name i wana printed if it dont know like i dont understand can any one help me pleas
    if you can this is my email s3368964@student.rmit.edu.au
    #include

    int main (){
    int UserAsk ;
    int UserName ;
    int UserAge;
    int UserSpeed;
    printf(“sir can i see y license?”);
    scanf(“%”,UserAsk);

    printf(“whats you name?”);
    scanf(“%abdi”,&UserName);

    printf(“how old are you sir”);

    scanf(“%d”,&UserAge);

    if(UserAge=40)

    printf(“Sir Are you drunk?”);
    scanf(“%d” , &UserSpeed);

    //Conditional Statment to Test if the Driver is drunk
    //if the user is not drunk, they are allowed to drive

    if(UserSpeed 70
    printf(“You drive safety speed thnx.”);

    }else{
    //This stuff runs only if the statement evaluates to <70
    printf("sir your speeding,mor then 70 km/h!");
    }
    getchar();
    getchar();

    return 0;
    }

  • Amy May 30, 2013, 3:46 pm

    Hotel Seri Malaysia has pointed you to build a room reservation system. The system required total of guest that will be insert by user. Then, the system allowed user to select appropriate rooms. There are 4 types of rooms with different of prizes and capacity. If the total guest balance is 1, the guest will suggested to share the room with others guest. Refer to when that has different prices and the amount of different people. Each room is given different discount value. Please refer to Table 1 for the detail.

    Table 1: Information of available rooms in Hotel Bayu.
    Room types Maximum (persons) Price (peak) Discount given
    Melur 1 150 10% off
    Kenanga 2 250 20% off
    Teratai (studio) 2 300 25% off
    Rafflesia (suite) 3 350 30% off

    Customer is required to pay a deposit of 50% of the actual price.

    Your system should have:
    1. Global declaration of all the variables and functions.
    2. 5 functions: function melur, function kenangan, function teratai, function rafflesia and calculate balance of person.
    3. In each function, you need to calculate the following items:
    a. Number of rooms
    b. Total price before discount
    c. Total price after discount
    d. Amount paid by customer
    e. Amount to be paid
    Below is the example of the formula to be used:
    Example of formula (for room type Kenanga) :
    num_of_rooms = num_of_people/2;
    before_discount = 250*num_of_rooms;
    after_discount = (before_discount-(0.20*before_discount))
    deposit = 0.5*after_discount;
    to_be_paid = after_discount-deposit;

    4. If there is a balance person that not allocated in the rooms, user needs to re-select the room.
    5. System will calculate total amount from the to_be_paid amount.

    Your program must use operators, control statements (for, do while or any equivalent) and at least 4 functions.

  • rokon June 22, 2013, 12:45 pm

    Take two number inputs and a arithmetic operator (+,-,*,/,%) as a character input and to the arithmetic operation and give the output. For example, Your output should be like this:

    Enter a number (A) : 3.0
    Enter a number (B) : 8.5
    Enter an operator : *

    A*B= 25.5

  • nimpha June 23, 2013, 12:59 pm

    i need a help using switch here is the question….
    Create a c program that will accept a value or amount prom peso and convert it based on a given choice of user
    Choice Currency AMOUNT
    1 YEN .50
    2 UAD 40.50
    3 USD 42.50
    4 EURO 62.25

  • Kevin July 17, 2013, 5:49 am

    guys can you help me?

    i need an example of if else statement that accept 3 numbers as input the identify the highest,lowest and middle value.

    anyone can help me. please! :(

  • Unell August 7, 2013, 2:50 pm

    can u help me to construct C program !!!! this is the question
    The XYZ telegram company charges 18.50 for telegrams do not exceed 12 words and
    1.50 pesos for every succeeding word. Construct a C program that accepts the number of words in a telegram compute and display the charge..

    can u help me about this !!!!! using turbo C

  • ashish saxena August 10, 2013, 6:58 am

    i want to convert numeric value to char valu(as 199).is but i wann to print (one hundered ninty nine) thi output

    plz tell me how this possibale thank you……

  • Shuvo August 19, 2013, 6:25 pm

    #include
    #include
    void main()
    {
    int a;
    while(‘N’)
    {
    printf(“\nEntr Your Marks: “);
    scanf(“%d”,&a);
    if(a>’39’&&a=’33’&&a<='39')

    printf("D\n\n");

    else if(a=’0′)printf(“F”);

    else

    printf(“Wrong Input. please Enter Marks 0 to 100.\n\t\t Thanks”);}
    getch();
    }

  • 3in@j August 27, 2013, 4:28 am

    Will u pls help me print this output? .:(
    Election Results
    Enter no. of precints: 3
    No. of votes:
    Precint 1: 10
    Precint 2: 13
    Precint 3:15
    Precint with highest votes: 3
    Precint with lowest votes: 1

  • Jerome agas August 30, 2013, 3:30 pm

    can you please help me to program . . .
    /*create the program that accepts three numbers and identify the largest, middle and smallest number if the two or three numbers are equal the output will be the two or three number are equal and smaller or larger

  • zamaal September 7, 2013, 5:27 pm

    1. Write a C program that asks user to input an amount, then display 5%, 10% and 15% discount of that amount. For example,
    Please input the amount:
    5% Discount =
    10% Discount=
    15% Discount=

  • muhammad anwar bin hassan al ashari September 12, 2013, 8:36 am

    use the If else programming, please do program below

    formula BMI = Weight(kg) / [Height(m) x Height (m)]

    Using program control to print below conditions;

    1.If Your BMI Less than 18.5, you are underweight
    2.If Your BMI is 18.5 less than 25, your weight is desirable
    3.If Your BMI is 25 to less than 30, your are overweight
    4.If Your BMI is 30 or more, you are obese

  • Naqash Ahmed October 11, 2013, 10:04 am

    develop a program to print the charges for a person,if he enter his age then program ask the user to enter his age and by using if else structure print the charges,if age is 55 and above it the charges is 10$ if age is 21 to 54 it charges is 15$ if age is 13 to 20 it charges is 8$ if age is 3 to 12 it charges is 5$ if under 3 no charges that will be free.
    plz snd me in cmplete c++ format

  • ahmad October 22, 2013, 12:34 pm

    how to print as below:
    4 4 4 4
    4 4
    4 4
    4 4 4 4
    when a user enters 7, it will printed:
    7 7 7 7 7 7 7
    7 7
    7 7
    7 7
    7 7
    7 7
    7 7 7 7 7 7 7
    when user enter 2, it will printed:
    2 2
    2 2

    The program should only allow a user to enter an integer from 1 to 9 in which the ‘Invalid integer’ will be displayed and user will be asked to reenter the integer from 1 to 9 again. After the rectangular shape has been printed, user should be asked whether they want to reenter another integer to reprint the other size of rectangular or they want to exit the program.

  • Fresnel November 9, 2013, 6:29 am

    Hey guys! Can you help me with this?

    Make a C++ program that will ask the user to input an alphabet character then will display the rest of the characters taking user’s input as its initial value.

    Example:
    Enter a small letter: r
    Output: r s t u v w x y

  • james January 12, 2014, 8:50 pm

    can i do sth like this ====> if (a==xxxx) {printf”you are ok “}
    else { you are not ok}
    where xxxx is a character . plz txt me back cuz i need it now . thnx :)

  • michael January 18, 2014, 11:28 am

    My Question:
    Call charges:1st minutes are free and 2.25 for each minutes.
    SMS chargers:0.25 per SMS(50 SMSs are free for month).
    Monthly rental is 300.00.
    Government taxes 12.5% of total bill amount.
    Write a suitable C program to calculate total bill(including taxes)when number of minutes and SMSs are given as input.
    Please tell me what’s the wrong with those code.When I run the program it did not work properly.

    int main()
    {
        printf("\t\tDialog Monthly Total Bill Amount-Version-R01\n");
        float x,y,Total1,Total2,Tatol3;
        {
            printf("Number of minute for call:",x);
            printf("Number of SMSs sent:",y);
        }
        if (x>200)
        {
            printf("call charge=(minutes-200)*2.25");
        }
        else
        {
            printf("call charge=0");
        }
        if (y<=50)
        {
            printf("SMS charge=0");
        }
        else
        {
            printf("SMS charge=SMS*0.25");
        }
        printf(Total1=(300+(call charge+SMS charge))*0.125));
        scanf("%f",Total1);
        {
            printf("Total1 is%0.2f",Total1)
        }
        return 0;
    
  • akanksha paithane January 29, 2014, 3:35 am

    explain if \else statement with its syntax which logical operation are user in false statement and how explain whith examples.

  • arbe February 23, 2014, 11:14 am

    hi,guys .. can you give me a example to create a program that deals in if then statement?

    thanks..

  • pooja mehta April 2, 2014, 9:52 am

    hello.my question is that what does it means
    1.if(;;)
    2.how we can infinitely use if condtion
    3.if(=)

  • janaki April 15, 2014, 12:49 pm

    please give me the solution for this programm

    if(?)
    {
    printf(“Hello”);
    }
    else
    {
    printf(“world”);

    what is the condition for get Output:”Hello World”
    }

  • Michael May 6, 2014, 6:15 am

    please i need help i want to know whats wrong with this my codes
    #include
    #include
    #include

    int main()
    {
    float price = 91;
    float quantity;
    float discount1 = 1 – 0.2;
    float discount2 = 1 – 0.3;
    float discount3 = 1 – 0.4;
    float discount4 = 1 – 0.5;
    float totalcost1 = price * quantity * discount1;
    float totalcost2 = price * quantity * discount2;
    float totalcost3 = price * quantity * discount3;
    float totalcost4 = price * quantity * discount4;

    printf(“\t Micro-world Technologies Discount Sales\n\n “);
    printf(” Please enter the quantity of items sold: \n”);
    scanf(“quantity is: %f\n”, &quantity);

    if(10 >= quantity = quantity = quantity <= 99){
    printf(" Total cost on 40percent discount is = %f\n", totalcost3);
    } else {
    printf(" Total cost on 50percent discount is = %f\n", totalcost4);
    }

    system("pause");
    return 0;
    }

  • Michael May 6, 2014, 6:18 am

    #include
    #include
    #include

    int main()
    {
    float price = 91;
    float quantity;
    float discount1 = 1 – 0.2;
    float discount2 = 1 – 0.3;
    float discount3 = 1 – 0.4;
    float discount4 = 1 – 0.5;
    float totalcost1 = price * quantity * discount1;
    float totalcost2 = price * quantity * discount2;
    float totalcost3 = price * quantity * discount3;
    float totalcost4 = price * quantity * discount4;

    printf(“\t Micro-world Technologies Discount Sales\n\n “);
    printf(” Please enter the quantity of items sold: \n”);
    scanf(“quantity is: %f\n”, &quantity);

    if(10 >= quantity = quantity = quantity <= 99){
    printf(" Total cost on 40percent discount is = %f\n", totalcost3);
    }
    else {
    printf(" Total cost on 50percent discount is = %f\n", totalcost4);
    }

    system("pause");
    return 0;
    }

  • wilson sanico June 12, 2014, 2:56 am

    help me to solve this problem
    ,, create a c++ program that will accept 3 integers an

  • elgo July 12, 2014, 10:48 am

    if input the distance traveled by a taxi in kilometer and then display the taxi fare based on the distance traveled. the flag down rate is $40 and additional $ 3.50 per 300 meters traveled.
    1km=1000meter

  • john August 1, 2014, 2:13 pm

    1. Create A program that will accept number between 1-40.
    2. Program will identify whether the number is HIGH or LOW category based from criteria.
    * HIGH —> 21-40
    * LOW —-> 1-20
    3. under low category each number falls on this must be labeled as above 10 or below 10, criteria.
    * ABOVE 10 = 11-20
    * BELOW 10 = 1-10
    4. program display the result.
    5. program close.

    OUTPUT:

    Enter number = 18

    18 is above 10 under low category.

    Enter number = 22

    22 is above 20 under high category.

    pls help me. im using DEV C++ 5.6.2.
    pls HELP me.

  • Ridoy Bhuiya August 2, 2014, 8:26 pm

    Please Help ME!!!!!

    Write a program in c that prompts the user to enter the year and a month of the year and displays the calendar table for the month of that year on the console…

    • Bernard August 18, 2014, 12:52 pm

      Can i Have a question??
      it can be happen if the state is IF ELSE statement inside has a SWITCH Statement?? it can be possible??

  • Lheii September 4, 2014, 2:03 pm

    Hello :)
    Please HELP ME! :D

    Create a program that can greet a person, it can repeat the greeting while the answer is yes and exit if no.

    ANSWER PLEASE? :)))

  • clariz September 17, 2014, 2:39 pm

    How to run this in c++ by using for loop only?
    Condition
    1.menu -> character
    If choice == “a”
    If choice == “b”
    If choice ==”c”
    2.choices use for loop(output= 1234567…)

    Menu
    a)print 1 to 10
    b)print odd number 1 to 20
    c)print even number between 1 to 20
    d)print hello 20 times

    Enter choice: a??

    Help me please

  • Theophilus Kweku Yawson October 7, 2014, 6:09 pm

    Please can any one help me write this program?
    Imperial Taxi Services (ITS) serves one-time passengers and regular clients
    (identified by a taxi card). The ITS taxi fares for one-time passengers are calculated as follows:
    1. Minimal fare: $2. This fare covers the distance traveled up to 1000 yards and waiting time (stopping for traffic lights or traffic jams, etc.) of up to 3 minutes.
    2. For every additional 250 yards or part of it: 25 cents.
    3. For every additional 2 minutes of stopping or waiting or part thereof: 20 cents.
    4. One suitcase: 0 change; each additional suitcase: $1.
    5. Night supplement: 25%, effective for journeys between 21.00 and 06.00 O’clock.
    Regular clients are entitled to a 10% discount and are not charged the night supplement.
    A) Provide the pseudo code for the above problem.
    B) Design a normal program for the taxi fare calculation process.
    C) Design a program using appropriate user-defined functions for the taxi fare calculation process.

  • osama October 15, 2014, 9:27 am

    write a c program to comment on user entered grade in either capital or small letter

  • Faheen Abbas October 15, 2014, 11:47 am

    I really don’t know that this site is running or not, Actually i need some program of if statement, if else statement, nested statement, loop statement, function, programs.
    actually i want 5 programs each one of it and using by function ……………please kindly refer to everyone to send me on my email: faheenabbas@gmail.com

  • loryf October 20, 2014, 7:52 am

    pls help me to make a program that will output the three conditional statement…

  • Shuvashis October 21, 2014, 5:09 pm

    Write a C program that will take three integer numbers and display the mid
    dle number.

  • autumn October 31, 2014, 8:37 am

    can anyone help me with this program,please?
    *a program that will accept a non-negative number and able to count how many odd or even numbers inputted by user loop will terminate if the user input negative number.

  • mais December 1, 2014, 1:12 pm

    please , i want the Solution today

    Write your name, student ID at the top of your program inside the comment.
    Write a C program that will ask the user various choices: ((use switch statement))
    Please make your selection:
    (1) for upright sideway triangle
    (2) for upside sideway triangle
    (3) for a triangle (not sideway)
    (4) triangle with letter A in the middle.
    Once a selection is made, ask the user for the height of the triangle.
    then print the requested triangle.
    Finally ask the user if he wants to continue. If yes then repeat the steps above. ((use so-while loop))
    Explanation:
    (1) upright-sideway triangle with height = 5.
    *
    **
    ***
    ****
    *****
    (2) upside sideway triangle with height = 5.
    *****
    ****
    ***
    **
    *
    (3) triangle with height = 5
    *
    ***
    *****
    *******
    *********
    (4) triangle with letter A in the middle with height = 4
    *
    *A*
    *A*A*
    *A*A*A*

  • infinity January 27, 2015, 9:02 am

    Guys need help! pls ans.
    Write a program that displays an equivalent color once an input letter matches its first character. For example b for Blue, r for Red, and so on. Here are the given criteria: (The letters as an input data and the color as output information).

    Letters Color
    ‘B’ or ‘b’ Blue
    ‘R’ or ‘r’ Red
    ‘G’ or ‘g’ Green
    ‘Y’ or ‘y’ Yellow
    Other letters “Unknown Color”

  • helpmeplease January 28, 2015, 8:30 am

    Please help me how to create a program that will add all the positive numbers inputted and all the negatives inputted.

  • abhinav narayan February 12, 2015, 2:27 pm

    i want to input an age of a student if the age is less than 18,print minor otherwise print major

  • nahian March 22, 2015, 6:35 am

    can anybody solve this program i made this program with char. please help ? only one error and two warning is showing in this program.the only error is “misplaced else in main function” and warning is “code has no effect in main function” i am using turbo C++

    #include
    int main()
    {
    char ILL,ch;
    printf (“ARE YOU ILL ?\n”);
    scanf(“%c%c”,&ILL,&ch);

    if( ch ==’y’|| ch ==’Y’);

    printf(” go to the hospital\n”);

    else

    printf(“then do your homework\n”);
    }

  • shenelle March 28, 2015, 2:36 pm

    can someone point out whats wrong with this code. it does not run and at this point i am terribly frustrated

    int main()
    {
        /*Declare Variables*/
        int done = 0;
        float sum = 0;
        char choice;
        float twix = 0.22;
        float hersheys = 0.30;
        float mars bar = 0.20;
        float sneaker bar = 0.25;
        printf("================CANDY STORE=================\n");
        printf("==========================================\n\n");
        printf("To buy a [T]wix bar press T(then enter)\n");
        printf("To buy a [H]ershys bar press H(then enter)\n");
        printf("To buy a [M]ars bar press M(then enter)\n");
        printf("To buy a [S]nicker bar press S(then enter)\n");
        printf("To [E]xit system press E (then enter)\n\n");
        while(!done)
        {
                    /*User Inputs*/
                    printf("Your choice: ");
                    scanf("%s",&choice);
                    /*Processing*/
                    swith(choice)
                    {
                          case 'T':
                               sum = sum + twix;
                               break;
                          case 'H':
                               sum = sum + hershys;
                               break;
                          case 'M':
                               sum = sum + mars bar;
                               break;
                          case 'S':
                               sum = sum + snicker bar;
                               break;
                          case 'E':
                               done = 1\n;
                               break;
                          default:
                                  printf("Invalid Selection\n");
                                  break;
                     }
        }
       /*Output*/
       printf("\nTotal: $%5.25f\n,sum);
       printf("\"Thanks for shopping! Come again!\"");
       getchar();
       getchar();
       return 0;
    }
    
  • subashri April 28, 2015, 2:10 pm

    Write a C program to print all numbers between a and b (a and b inclusive) using a for loop.

  • sabir May 21, 2015, 9:34 am

    i need a program which can take a Character as a input and show their ASCII Code

  • navi June 4, 2015, 2:15 pm

    Write a C program to print all numbers between a and b (a and b inclusive) using a for loop.

  • ayoola June 7, 2015, 8:33 pm

    This code is giving me these errors “expected initializer before ‘printf'” and “names not declared.” this is d code…
    #include
    int main()
    {

    int name;
    char name[]
    printf(“\n Enter the name \n” );
    scanf(“%s”, &name);
    if(name==Laide)
    {
    printf(“\n Score:42 Remark:Fail Position:5th \n”);
    }
    else
    {
    printf(“Pass”);
    }
    printf(“\n Enter the name of a student: \n” );
    scanf(“%s”, &student);
    if(student==Kehinde)
    {
    printf(“\n Score:64 Remark:Pass Position:4th \n “);
    }
    else
    {
    printf(“Fail”);
    }
    printf(” \n Enter the name of a student: \n ” );
    scanf(“%s”, &student);
    if(Name==Femi)
    {
    printf(” \n Score:78 Remark:Pass Position:2nd \n “);
    }
    else
    {
    printf(“Fail”);
    }
    printf(” \n Enter the name of a student: \n ” );
    scanf(“%s”, &student);
    if(name==Femi)
    {
    printf(“\n Score:87 Remark:Pass Position:1st \n “);
    }
    else
    {
    printf(“Fail”);
    }
    printf(“\n Enter the name of a student: \n ” );
    scanf(“%s”, &student);
    if(name==Jumoke)
    {
    printf(” \n Score:69 Remark:Pass Position:2nd \n”);
    }
    else
    {
    printf(“Fail”);
    }
    return 0;
    }

  • Satyam June 21, 2015, 10:23 am

    I need a C program for converting the Date format input as 01/01/2015 to the Output date format 1st,January,2015 using switch case only..

  • PUVEN July 15, 2015, 2:45 pm

    I need help from you guys.

    I’m required to write a program to calculate the utility bill.

    its 20 cents for the first 100 unit
    25cents for the next 200 unit
    and 28 cents for every additional unit.
    the number of reading is based on the current meter reading and the previous meter reading.the bill also includes the fixed charge that is rm 35.00.

  • Waseem Hassan August 7, 2015, 6:18 pm

    how to add two dates?

Leave a Comment