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;
}
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 83 comments… read them below or add one }
i need more information about “if else”
#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”, §ion);
printf(“Enter the grade of a student: “);
scanf(“%d”, &grade);
if(grade>75)
printf(“PASSED”);
else
print(“FAILED”);
getch();
}
require more explanation
and examples
i need the answer for small and greatest number in 10 numbers
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.
I need more program about if else
#include
#include
main()
{
int age;
clrscr();
printf(“Enter the age:”);
scanf(“%d”, &a);
if(a<18)
printf("can't vote");
else
printf("can vote");
}
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”);
}
why we use y%4.show me answer
y%4
that means which value is store in y that is divided by 4
% is a modular
the year divided by 4, get remainder zero ,is leap year.
can you convert this to java program?
I just study programming .
hello all..exiting ang programming nuh?haha
how to analyze the problem to make c program?tnx
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.
Super Example For If Statement
i’m excited to try this program
i need to create program right now for my project …………….help me …………………hehehe using IF ELSE STATEMENT
Give me another example of IF ELSE STATEMENT
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
Your homework is very easy just use the
if(user>=75)
printf(“A”);
else if(user>=60 && user<=74)
printf("B");
and so on.
did you manage to get the answer?
did anyone mailed you?
thanks
sujesha
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();
}
thank u..
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
Hello
make sure you use the proper braces before and after else statement.
can you give more examples :-)
Thanks I love you!!
pls. give me a program example of official receipt of sm using if else statement pls. we need it badly…pls…thanx
why can’t I place another “if statement” inside and “if statement”?
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
can you give me the def of if family statements
Use indentations ur prblm wl be solved
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:
#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;
}
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
Thanx for help my study
Make a C program that will accept any integers from 1-12 and displays equivalent month, Example if 3 “March”.
i need more explanation of if-esle statement also example….
how to find square root of a number by using if else in c program?
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..
-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;
}
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
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
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”);
}
}
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
please give me a code using array and function
i need more informations of c programs.
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,
can you help me in making calc with frem
i want more in formation about the if else statement.
i want to know more abt if else
#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;
}
even though compiler says “succes” .i can’t run the program it says elseif statement error
can u help me to get the c code of this….
enter the first no:20
enter the second no:30
selection operation:+,-,/,%
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..!!!
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%
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)
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!
i require a c program by using if else statement to print smallest of given four numbers
i require a c program by using if else statement to print smallest of given four numbers
please email me
i want more in formation about the if else statement.
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!!!!!
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.
good and interesting
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
write a c program that will get 4 integers and will print out the maximum integer…can anyone solve this?
i have some problem’s in if else statements or give me suggestion how i read about it
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.
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??
thankz a lot
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”.
Plss. .help me about this problem. . . .
i want the program to fing greatest among 4 numbers using nested if else ladder
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!!!!!!!!!!!
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..
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..
can
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
–>> 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.
Nice to see this site.
am learning c language from this cyberciti.biz web site. its really good to learn c for freshers.