#% help

20 messages · Page 1 of 1 (latest)

royal cloud
#

like i know % operator is use to give output of its remainder but where it is used for ?
like + , we can use it for adding sum / numbers
like * , we can use it for multiplication
but what is use of % operator , any real life example if anybody knew ?

alpine cradleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

unreal gazelle
#

the most basic one if for understanding if the number is even or not

#
#include <iostream>
using namespace std; 
int main(){
int even_number = 12,number = 11; 
if(even_number%2==0)
cout<<"its even"<<'\n'; 
if(number % 2 == 0)
cout<<"even"<<'\n'; 
else 
cout<<"not even"; 
return 0; }```
dusty oarBOT
#
Program Output
its even
not even
unreal gazelle
#

it can be used to get the last integer in the number, last 2 integers, so on

#

it can be done by %10 (in order to get last integer) or %100 (in order to get last 2 integers)

#

there are a lot of uses, you will understand them after you gain some experience by solving tasks

royal cloud
#

what is its use

royal cloud
unreal gazelle
#

1234/100 = 12.34

#

it will cout<<34

#
#include <iostream>
using namespace std; 
int main(){
cout<<1234%100<<'\n'<<1234%10<<'\n'<<1234/1000;
return 0; }```
dusty oarBOT
#
Program Output
34
4
1
alpine cradleBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.