If else statement in C Program

by on August 16, 2007 · 172 comments· last updated at August 16, 2007

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;
}


You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 172 comments… read them below or add one }

1 ferdinand v. baguingay December 10, 2008 at 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;
}

Reply

2 genji July 2, 2010 at 12:05 pm

i need more information about “if else”

Reply

3 merc velasco August 2, 2011 at 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();
}

Reply

4 Amit February 28, 2013 at 7:23 am

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

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

Reply

5 mira March 2, 2013 at 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

Reply

6 amit March 4, 2013 at 11:52 am

yes mira i also mean the same

Reply

7 twinkle September 2, 2011 at 10:14 am

require more explanation
and examples

Reply

8 Ratnesh February 12, 2012 at 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
}

Reply

9 affrin January 2, 2012 at 10:54 am

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

Reply

10 ashutosh sharma April 2, 2013 at 5:00 am

why we use return 0 in the last of program

Reply

11 nazmul January 27, 2009 at 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.

Reply

12 ankita May 5, 2010 at 1:28 pm

I need more program about if else

Reply

13 Meera. M May 25, 2010 at 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");
}

Reply

14 sreekanth October 8, 2010 at 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

Reply

15 addie stha September 1, 2011 at 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;
}

Reply

16 Chichaii January 14, 2013 at 12:06 pm

i need a example w/ no limitation..

Reply

17 ashutosh sharma April 2, 2013 at 5:16 am

there is error about voat.it gives only cannot voat

Reply

18 Bharath July 21, 2010 at 9:34 am

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

Reply

19 Sharad Puri May 26, 2011 at 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”);

}

Reply

20 rin August 3, 2011 at 8:57 am

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

Reply

21 tyaiba August 25, 2011 at 12:01 pm

why we use y%4.show me answer

Reply

22 adil August 26, 2011 at 2:55 pm

y%4

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

Reply

23 Amit February 28, 2013 at 7:37 am

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

Reply

24 azizur rahman October 7, 2011 at 5:25 am

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

Reply

25 Ratnesh February 12, 2012 at 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”);
}
}

Reply

26 aldrin March 22, 2009 at 1:34 pm

can you convert this to java program?

Reply

27 saviye.saviyola April 21, 2009 at 4:01 am

I just study programming .

Reply

28 alyssa mae cruz July 6, 2009 at 8:01 am

hello all..exiting ang programming nuh?haha

Reply

29 markjasonarceo September 21, 2009 at 9:45 am

how to analyze the problem to make c program?tnx

Reply

30 carrys September 24, 2009 at 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.

Reply

31 Pooja Sree December 3, 2009 at 5:15 am

Super Example For If Statement

Reply

32 BharathSVK July 21, 2010 at 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");
}

Reply

33 kalpana March 7, 2012 at 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);
}
}
}

Reply

34 allen joyce December 15, 2009 at 5:55 am

i’m excited to try this program

Reply

35 allen joyce December 15, 2009 at 5:57 am

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

Reply

36 allen joyce December 15, 2009 at 5:58 am

Give me another example of IF ELSE STATEMENT

Reply

37 kalpana March 7, 2012 at 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”);
}

Reply

38 bayan December 23, 2009 at 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

Reply

39 Kenny June 19, 2010 at 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.

Reply

40 sujesha October 2, 2010 at 12:20 pm

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

Reply

41 riyas October 31, 2010 at 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();
}

Reply

42 myrabelle cabriana March 8, 2011 at 4:59 am

thank u..

Reply

43 emxif January 22, 2010 at 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

Reply

44 vince July 27, 2010 at 4:36 am

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

Reply

45 ali March 3, 2011 at 8:38 pm

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

Reply

46 JD October 8, 2011 at 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

Reply

47 Glenn February 3, 2010 at 2:26 am

can you give more examples :-)

Reply

48 Levi February 18, 2010 at 1:21 am

Thanks I love you!!

Reply

49 mabel March 6, 2010 at 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

Reply

50 Darren March 9, 2010 at 11:47 pm

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

Reply

51 KAJI April 14, 2010 at 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

Reply

52 venkata sai November 12, 2010 at 4:05 am

can you give me the def of if family statements

Reply

53 vishu May 26, 2010 at 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;
}

Reply

54 Muneeb zargar June 1, 2010 at 4:23 pm

Use indentations ur prblm wl be solved

Reply

55 reyjohn June 24, 2010 at 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:

Reply

56 IT_Specialist June 26, 2010 at 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;
}

Reply

57 arlyn July 5, 2010 at 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

Reply

58 Dyulokdyuti July 8, 2010 at 1:34 am

Thanx for help my study

Reply

59 angel August 16, 2010 at 1:19 am

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

Reply

60 anonimous August 25, 2010 at 1:25 pm

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

Reply

61 ... August 25, 2010 at 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”);
}
}

Reply

62 jane krizia hailar August 23, 2010 at 1:00 am

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

Reply

63 teoh September 5, 2010 at 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

Reply

64 chetan gupta September 14, 2010 at 5:12 pm

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

Reply

65 Jason October 15, 2010 at 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..

Reply

66 Queen13 December 14, 2010 at 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;
}

Reply

67 edison layco January 10, 2011 at 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

Reply

68 emi January 10, 2011 at 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

Reply

69 sonu asati October 3, 2011 at 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();
}

Reply

70 ratnesh February 6, 2011 at 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”);
}
}

Reply

71 wiwie69 March 3, 2011 at 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

Reply

72 joy March 22, 2011 at 7:21 am

please give me a code using array and function

Reply

73 renu April 2, 2011 at 7:32 am

i need more informations of c programs.

Reply

74 aklima akther April 21, 2011 at 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,

Reply

75 tejas May 27, 2011 at 1:22 pm

can you help me in making calc with frem

Reply

76 sagal paudel June 2, 2011 at 1:34 pm

i want more in formation about the if else statement.

Reply

77 ramadhan kabange June 28, 2011 at 3:50 pm

i want to know more abt if else

Reply

78 arpit mishra August 8, 2011 at 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;
}

Reply

79 anver va July 21, 2011 at 12:49 pm

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

Reply

80 jheremie rochina July 23, 2011 at 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:+,-,/,%

Reply

81 mj calago August 12, 2011 at 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..!!!

Reply

82 Hanna August 22, 2011 at 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%

Reply

83 Dianne August 26, 2011 at 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

Reply

84 vaishali August 27, 2011 at 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)

Reply

85 leecel August 29, 2011 at 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!

Reply

86 umesh kumar vishwakarma August 31, 2011 at 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();
}

Reply

87 harisha September 14, 2011 at 2:04 pm

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

Reply

88 Cool Gtm March 25, 2012 at 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()
}

Reply

89 harisha September 18, 2011 at 8:31 am

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

Reply

90 divya s September 19, 2011 at 8:05 am

i want more in formation about the if else statement.

Reply

91 Monica September 20, 2011 at 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!!!!!

Reply

92 Peter B. September 26, 2011 at 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.

Reply

93 sonu asati October 5, 2011 at 12:32 pm

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

Reply

94 mutuzo ruth October 7, 2011 at 7:19 am

good and interesting

Reply

95 leah October 10, 2011 at 9:30 am

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

Reply

96 Andrei de Luna October 11, 2011 at 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

Reply

97 Maria Moosa October 12, 2011 at 6:45 pm

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

Reply

98 sumit October 24, 2011 at 3:31 am

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

Reply

99 Utku October 29, 2011 at 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.

Reply

100 sri November 5, 2011 at 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);

}

Reply

101 sri November 5, 2011 at 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.

Reply

102 hira November 8, 2011 at 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…

Reply

103 Jibril November 17, 2011 at 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..

Reply

104 Jibril November 17, 2011 at 2:27 pm

follow up ! using DEV c++ compiler …

Reply

105 jia November 28, 2011 at 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?

Reply

106 janani December 2, 2011 at 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..

Reply

107 Patricia December 8, 2011 at 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??

Reply

108 prabhat December 8, 2011 at 1:43 pm

thankz a lot

Reply

109 Joseph December 10, 2011 at 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

Reply

110 Joseph December 10, 2011 at 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;
}

Reply

111 Md.Akbar December 13, 2011 at 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();
}

Reply

112 pradeep kumar October 18, 2012 at 1:15 pm

good

Reply

113 Hak December 22, 2011 at 1:22 pm

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

Reply

114 student December 24, 2011 at 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.

Reply

115 muru October 5, 2012 at 9:40 am

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

Reply

116 Brendon October 13, 2012 at 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”".

Reply

117 Deepak Jain November 2, 2012 at 5:56 am

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

Reply

118 SATYARANJAN DAS December 24, 2011 at 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();
}

Reply

119 pop December 24, 2011 at 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

Reply

120 Mohamad Mostafa January 8, 2012 at 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”);
}

Reply

121 khushi October 18, 2012 at 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();
}

Reply

122 hansel January 22, 2012 at 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”.

Reply

123 rajeeva February 26, 2012 at 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,=)

Reply

124 rosen September 12, 2012 at 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();
}

Reply

125 hansel January 22, 2012 at 3:17 am

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

Reply

126 sangeetha January 25, 2012 at 2:14 pm

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

Reply

127 Anna January 30, 2012 at 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!!!!!!!!!!!

Reply

128 enkeli February 4, 2012 at 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..

Reply

129 enkeli February 4, 2012 at 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..

Reply

130 skret February 9, 2012 at 5:32 am
131 skret February 9, 2012 at 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

Reply

132 Reccalyn Castillo February 9, 2012 at 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.

Reply

133 shiva February 9, 2012 at 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.

Reply

134 hassan February 10, 2012 at 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

Reply

135 Cool Gtm March 25, 2012 at 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();
}

Reply

136 arnel March 22, 2013 at 3:02 pm

what does ch means? i dk, sorry explain.

Reply

137 swapna yadav February 17, 2012 at 7:55 am

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

Reply

138 arnel March 22, 2013 at 3:02 pm

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

Reply

139 Ahsin Khan February 21, 2012 at 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……!!!!

Reply

140 Cool Gtm March 25, 2012 at 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();
}

Reply

141 mary faith February 24, 2012 at 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

Reply

142 sandhya March 13, 2012 at 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.

Reply

143 Reshma Rajeev April 1, 2012 at 6:58 am

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

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

Reply

144 shadik August 9, 2012 at 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.

Reply

145 anum shakir April 24, 2012 at 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

Reply

146 Ly po May 12, 2012 at 11:53 am

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

Reply

147 sitesh September 22, 2012 at 4:08 am

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

Reply

148 Rajat May 14, 2012 at 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)

Reply

149 darmie May 19, 2012 at 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

Reply

150 Hozefa May 26, 2012 at 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();}

Reply

151 dorothy June 12, 2012 at 6:26 am

so nice answers are provide and sharing

Reply

152 Sandeep Chaurasia August 7, 2012 at 4:46 pm

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

Reply

153 Poorva August 22, 2012 at 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();
}

Reply

154 Tanvir Hossain October 17, 2012 at 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.

Reply

155 Dilip kumar December 18, 2012 at 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();
}

Reply

156 santosh January 9, 2013 at 7:01 am

i need while loop examples

Reply

157 vidhya January 15, 2013 at 3:30 am

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

Reply

158 vidhya January 15, 2013 at 3:01 am

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

Reply

159 romeje January 15, 2013 at 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.

Reply

160 Yogesh January 16, 2013 at 2:58 am

Can anyone clarify on me, on below statement,

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

Reply

161 vidhya January 25, 2013 at 11:57 am

hai, i want to know about while loop

Reply

162 navya January 26, 2013 at 7:35 am

give the syntax of simple if statement in c

Reply

163 soumen dofadar January 26, 2013 at 5:30 pm

good…but not enough to understand clearly…..

Reply

164 Siddarth February 5, 2013 at 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;
}

Reply

165 kartikpareek February 10, 2013 at 8:26 am

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

Reply

166 krishan kant azad February 24, 2013 at 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();
}

Reply

167 neeraj March 21, 2013 at 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.

Reply

168 manoo March 25, 2013 at 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.

Reply

169 manoo March 25, 2013 at 8:07 pm

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

Reply

170 sohaimey March 26, 2013 at 11:43 am

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

Reply

171 newbie March 30, 2013 at 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.. ^_^

Reply

172 Roy May 14, 2013 at 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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , ,

Previous Faq:

Next Faq: