See a problem in else if statement

Dangling else problem

Image
Hello, This problem comes when we use else if statement and do some mistake more describe is given below......... Dangling else problem: One of the major problem with nested if is dangling else problem. The problem arises when both outer if statement inner if statement might pair with common else statement. Thus the compiler is not able to judge to pair the else with which statement. The solution to this problem is given by the compiler that it pairs else with the recent if thus sometimes giving wrong result.                                           Hence the programmer should put early bracket wherever required. This post is may very short because my only aim was to describe this problem. Thank you, Keep supporting............. 

Looping part 3(examples)

In this post we define every loop by example and show you difference between them-

Important point of for loop-

There are three fields in the for loop which can be left vacant but initialization of counter variable should be done before the loops start executing as well as the counter is done with in the loop. If no condition is given with in the for statement by default it evaluates to be true.

Infinite loop:

Infinite loop means the body of the loop will executed infinitely without manual interaction this happens because the given test expression never evaluate to be false.

Difference between do while and while loop use:

 for loop example:

wap to find out sum of even no. between 1 to n.


#include<stdio.h>
main()
{
int i=1,n,sum=0;
printf("Enter the range:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==2)
sum=sum+i;
}
printf("Sum=%d",sum);
}

while loop example:

Wap to find out sum of first n no.-
#include<stdio.h>
main()
{
int i=1,n,sum=0;
printf("Enter the range:");
scanf("%d ",&n);
while(i<=n)
{
sum=sum+i;
i++
}
printf("Sum=%d",&sum);
}
Thank you,
If any question in your mind please comment below.........

Comments

Popular posts from this blog

Libraray Fine Hackerrank solution in C || Balanced Brackets Hackerrank solution in C

Permutations of Strings hackerrank solution in C || Permutations of Strings

Introduction to C part 2