if else statement in c program

Upload: dayanand-sagar

Post on 16-Jul-2015

1.685 views

Category:

Documents


0 download

TRANSCRIPT

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

About Blog Forum Low graphics Shell Scripts RSS/Feed

INDIAN RAILWAYS PASSENGER RESERVATION ENQRail Logo Linux FAQ / HowtosPassengers are requested to carry ID proof in upper classes(First AC,Second AC,Third while undertaking the journey w.e.f. 15-02-2012

If else statement in C Programby Vivek Gite on August 16, 2007 88 comments 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 syntaxGeneral 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 exampleFollowing example will find out large number from given input:#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; }

Featured Articles:

1 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

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 Share this with other sys admins! 1 Facebook it - Tweet it - Print it { 88 comments read them below or add one } 1 ferdinand v. baguingay December 10, 2008#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 i need more information about if else Reply 3 merc velasco August 2, 2011 #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);

2 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

getch(); } Reply 4 twinkle September 2, 2011 require more explanation and examples Reply 5 Ratnesh February 12, 2012 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 6 affrin January 2, 2012 i need the answer for small and greatest number in 10 numbers Reply 7 nazmul January 27, 2009 I need more if else program.i have simple problem.i dont know your wbsite is active or not.next time i give a problem please solve it. Reply 8 ankita May 5, 2010 I need more program about if else Reply 9 Meera. M May 25, 2010 #include #include main() { int age; clrscr(); printf(Enter the age:); scanf(%d, &a); if(agernum) { printf(The number is Greater); } else{ printf(The number is smaller); } } Reply 15 aldrin March 22, 2009 can you convert this to java program? Reply 16 saviye.saviyola April 21, 2009 I just study programming . Reply 17 alyssa mae cruz July 6, 2009 hello all..exiting ang programming nuh?haha Reply 18 markjasonarceo September 21, 2009 how to analyze the problem to make c program?tnx Reply 19 carrys September 24, 2009 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 20 Pooja Sree December 3, 2009 Super Example For If Statement Reply 21 allen joyce December 15, 2009 im excited to try this program

5 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

Reply 22 allen joyce December 15, 2009 i need to create program right now for my project .help me hehehe using IF ELSE STATEMENT Reply 23 allen joyce December 15, 2009 Give me another example of IF ELSE STATEMENT Reply 24 bayan December 23, 2009 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=Agrade 60-74=Bgrade 50-59=cgrade 40-49=Dgrade Below 40=Fail thanks . please send it to my Email [email protected] Reply 25 Kenny June 19, 2010 Your homework is very easy just use the if(user>=75) printf(A); else if(user>=60 && useri &7) mean and in last for loop what does i -= 3 mean.how is it related to convert12 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

octal.can anyone please help me this, Reply 54 tejas May 27, 2011 can you help me in making calc with frem Reply 55 sagal paudel June 2, 2011 i want more in formation about the if else statement. Reply 56 ramadhan kabange June 28, 2011 i want to know more abt if else Reply 57 arpit mishra August 8, 2011 #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 58 anver va July 21, 2011 even though compiler says succes .i cant run the program it says elseif statement error Reply 59 jheremie rochina July 23, 2011 can u help me to get the c code of this. enter the first no:20 enter the second no:30 selection operation:+,-,/,% Reply 60 mj calago August 12, 2011 can you give me a program for votation?? dat would also count the votes and declare who will win !!! please??? im begging you guys..!!!

13 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

Reply 61 Hanna August 22, 2011 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 62 vaishali August 27, 2011 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 63 leecel August 29, 2011 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 64 harisha September 14, 2011 i require a c program by using if else statement to print smallest of given four numbers Reply 65 harisha September 18, 2011 i require a c program by using if else statement to print smallest of given four numbers please email me Reply 66 divya s September 19, 2011 i want more in formation about the if else statement. Reply 67 Monica September 20, 2011 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

14 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

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 68 Peter B. September 26, 2011 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 69 mutuzo ruth October 7, 2011 good and interesting Reply 70 Andrei de Luna October 11, 2011 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 71 Maria Moosa October 12, 2011 write a c program that will get 4 integers and will print out the maximum integercan anyone solve this? Reply 72 sumit October 24, 2011 i have some problems in if else statements or give me suggestion how i read about it Reply 73 Utku October 29, 2011 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 :

15 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

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 74 Patricia December 8, 2011 help me please. I need to make a program entering someones birthday and the current date today and it will identify your age. How?? Reply 75 prabhat December 8, 2011 thankz a lot Reply 76 hansel January 22, 2012 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 77 hansel January 22, 2012 Plss. .help me about this problem. . . . Reply 78 sangeetha January 25, 2012 i want the program to fing greatest among 4 numbers using nested if else ladder Reply 79 Anna January 30, 2012 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.. [email protected] May God will pay back you for your kindness.. Thank you so much!!!!!!!!!!! Reply 80 enkeli February 4, 2012 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..

16 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

Reply 81 enkeli February 4, 2012 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 82 skret February 9, 2012 can Reply 83 skret February 9, 2012 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 84 Reccalyn Castillo February 9, 2012 >> 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 85 shiva February 9, 2012 Nice to see this site. am learning c language from this cyberciti.biz web site. its really good to learn c for freshers. Reply 86 hassan February 10, 2012 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 87 swapna yadav February 17, 2012 can anyone say me y do v use == instead =

17 of 20

3/6/2012 9:02 PM

If else statement in C Program

http://www.cyberciti.biz/faq/if-else-statement-in-c-program/

Reply 88 Ahsin Khan February 21, 2012 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 statementsis there any one who can solve itplease let make it solve quickly its assignment!!!! Reply Leave a Comment Name * E-mail * Website

You can use these HTML tags and attributes for your code and commands:

  • Notify me of followup comments via e-mail Security Question:What is 9 + 9 ?Solve the simple math so we know that you are a human and not a bot.Ads by GoogleC ProgrammingExampleTurbo CC ProgramsTagged as: c program, gnu linux, if else syntax, linux gcc, tcPrevious post: Redhat enterprise Linux / CentOS installing kernel source code Next post: Linux / Unix: Checking Free Disk SpaceGET FREE TIPSMake the most of Linux Sysadmin work!42000+ Subscribers | Twitter | Google +18 of 203/6/2012 9:02 PMIf else statement in C Programhttp://www.cyberciti.biz/faq/if-else-statement-in-c-program/Find us on FacebooknixCraftLike 19,641 people like nixCraft.StephenNirajSanjeevAsimShuNaveenOkkarChandraDylanNgocFacebook social plugin19 of 203/6/2012 9:02 PMIf else statement in C Programhttp://www.cyberciti.biz/faq/if-else-statement-in-c-program/Related FAQsHowTo: Use Oracle / MySQL SQL Commands In UNIX Shell Scripts Howto: Call Shell Script function In echo statement Bash While Loop Example BIND: Stop Recursion DNS Under Linux / UNIX How do I enable SQL *Plus Up and down arrow keys?2006-2012 nixCraft. All rights reserved. Cannot be reproduced without written permission. Privacy Policy | Terms of Service | Questions or Comments | Sitemap20 of 203/6/2012 9:02 PM