This is a discussion on problems in C within the C and C++ Programming forums, part of the Software Development category; i have problem in C language in if else or loope...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| i have problem in C language in if else or loope |
|
#2
| |||
| |||
| which kind of problems you faced in loop or array ? |
|
#3
| |||
| |||
| Please explain about loop or Array...??? |
|
#4
| |||
| |||
| if This Happens, Do This... else Do This... CONDITIONAL BRANCHING is a term that is used to describe the way program flow diverges, depending on certain condition(s). if statements play an important role in conditional branching and their usage is quite easy to get the hang of. After typing if, you put the condition in a pair of brackets, followed by a statement you want the program to read if the condition expression returns a non zero value. If you want multiple statements, use a statement block. If the condition returns zero, sometimes you want the program do something else. In that case, after the if statement, you use an else statement. This time, there is no need for a condition. Once again, you can use a single statement or a statement block for multiple statements. #include <stdio.h> int main() { int a; printf("Input an integer and push return:\n"); scanf("%d", &a); if (a%2==0 && a%5==0) { /* Start of if block */ printf("%d is a multiple of 2 and 5\n", a); } /* End of if branch */ else { /* This is the else branch */ printf("%d is not a multiple of both 2 and 5\n", a); } /* End of if block */ return 0; } The program output for this example will depend on the value you enter. This example covers recent material, like using the printf and scanf functions, relation and logical operators, and finally the if and else statements. The printf functions are simple enough, but scanf reads in an integer (due to the %d format specifier), and assigns it to the int declared variable, a. a%2==0 && a%5==0 is the condition part of the if statement - it is surrounded by a pair of brackets. If I wanted to, I could've made this a little more readable by adding more brackets, like this: if ((a%2==0) && (a%5==0)) Onto the condition itself... recall that a%2 returns the remainder of the division of a by 2. If zero is returned, then a must be a multiple of 2. Similarly, a%5 returns zero if a is a multiple of 5. Now, a%2==0 returns 1 (true) if a%2 is equal to 0. Similar story for a%5==0. a%2==0 && a%5==0 returns 1 if BOTH operands of the && operator return 1. In that case, the if branch is executed, and the else branch is ignored. If a%2==0 && a%5==0 returns 0, the else branch is executed and the if branch is ignored. Notice how I've added curly brackets, despite having only one statement after the if and else statements. I have a habit of doing that, as it makes the code more readable in some ways. The following would've worked fine: if (a%2==0 && a%5==0) printf("..."); else printf("..."); |
|
#5
| |||
| |||
| Hello, When i coded the loops the for loop is not running properly it jump for the another loop. Please help me. ![]() |
|
#6
| |||
| |||
| Quote:
Thanks for your given information. |
|
#7
| |||
| |||
| Quote:
Can you put your for loop code here ? Then, I can solve it for you. Last edited by arjkhanna : 09-24-2009 at 07:42 PM. |
|
#8
| |||
| |||
| I was looking for that C problem solution. Thanks hkp819 for sharing that information. Last edited by arjkhanna : 09-24-2009 at 07:42 PM. |
|
#9
| |||
| |||
| Hi, I can suggest you that c porogramming is not a difficult task.When we get everything right we become happy,but when we are stuck in anything we get frustrated .Inspite of rubbing our brains we just need to concentrate on the syntax or the coding . As you said that you are getting some problem in loops so you need to just check the syntax and the condition that you have given to the loop that's it. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PayPal problems | nhoj | eCommerce | 5 | 02-07-2008 09:42 AM |
| Networking problems | ventyra | Networking & Internet Connectivity | 0 | 12-05-2007 01:07 AM |
| Update to IE7 but the ActiveX Problems | montyauto | HTML, CSS and Javascript Coding Techniques | 1 | 05-25-2007 12:18 AM |
| VC++ Problems & Solutions | Karpagarajan | C and C++ Programming | 1 | 04-10-2007 02:36 AM |
Our Partners |