IT Community - Software Programming, Web Development and Technical Support

problems in C

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...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 10-14-2008, 01:59 AM
PPP PPP is offline
D-Web Trainee
 
Join Date: Oct 2008
Posts: 2
PPP is on a distinguished road
Default problems in C

i have problem in C language
in if else or loope
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 10-16-2008, 09:16 PM
JIYA JIYA is offline
D-Web Trainee
 
Join Date: Oct 2008
Posts: 2
JIYA is on a distinguished road
Smile Re: problems in C

which kind of problems you faced in loop or array ?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 10-21-2008, 01:48 AM
WebmasterR WebmasterR is offline
D-Web Trainee
 
Join Date: Oct 2008
Posts: 2
WebmasterR is on a distinguished road
Cool Re: problems in C

Please explain about loop or Array...???
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 12-19-2008, 06:49 PM
hkp819 hkp819 is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 41
hkp819 is on a distinguished road
Default if and else Statements

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("...");
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 12-26-2008, 02:39 AM
Sara Sara is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 2
Sara is on a distinguished road
Default Re: problems in C

Quote:
Originally Posted by JIYA View Post
which kind of problems you faced in loop or array ?
Hello,
When i coded the loops the for loop is not running properly it jump for the another loop. Please help me.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 01-07-2009, 08:55 PM
Manju Manju is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 2
Manju is on a distinguished road
Default Re: if and else Statements

Quote:
Originally Posted by hkp819 View Post
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("...");
Hi,
Thanks for your given information.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 02-16-2009, 06:33 PM
smith2009 smith2009 is offline
Banned
 
Join Date: Feb 2009
Posts: 3
smith2009 is on a distinguished road
Default Re: problems in C

Quote:
Originally Posted by Sara View Post
Hello,
When i coded the loops the for loop is not running properly it jump for the another loop. Please help me.
Hey,

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 04-15-2009, 08:49 AM
poster_boy poster_boy is offline
D-Web Trainee
 
Join Date: Apr 2009
Posts: 1
poster_boy is on a distinguished road
Default Re: problems in C

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 04-28-2009, 05:39 PM
kamlakar kamlakar is offline
D-Web Trainee
 
Join Date: Apr 2009
Posts: 4
kamlakar is on a distinguished road
Default c programming

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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


All times are GMT -7. The time now is 06:57 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0