Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how can print without else statement in if loop in c programming

0 votes
asked Apr 30, 2019 by harsha
write a c program to display "hi'" when a number is divisable by 3 and display "hello" when divisible by 5 and "hihello" when divisible by both 3 and 5

1 Answer

0 votes
answered Apr 30, 2019 by Xavier Navarro (140 points)
edited Apr 30, 2019 by Xavier Navarro

well, first of all, there is no if loop, there's a for loop, if that is what you mean and if you're talking about if statement then the set up is this:
 


if (this is true then...)

{

    this

}

else   // if not then...

{

    that

}


if you want to use the if statement then you have to use else because if the statement in the parenthesis isn't true then it has no output for if it's not true. If you simply want to leave the output for else out then you do this ( put nothing in else curly brackets).


if ( this is true then...)

{

      this 

}

else

{

}

continue code right here...

commented May 1, 2019 by anonymous
if(num/3)
{
printf("hi");
}
else if(num/5)
{
printf("hello\n");
}
else if((num/3)&&(num/5))
{
printf("hihello\n");
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...