Any wanna give explanation of this programs output?

General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
Post Reply
yobrekcah
New Member
Posts: 1
Joined: Sat Oct 15, 2011 12:23 pm

Any wanna give explanation of this programs output?

Post by yobrekcah »

#include <stdio.h>

int main(){
int a;
int b = 4 ;
int c;
b*=b;

for (a =1; a<b; ++a)
{
if(a%3 == 0 && a>3)
{
for (c=0; c< a-8 ;c++)
{
printf("%d\n", c);
}
}
}
system("pause");
return (1);
}

The output is this

0
0
1
2
3
0
1
2
3
4
5
6

regards!
User avatar
Mad_Haggis
Senior Member
Posts: 4128
Joined: Sun Mar 07, 2004 12:00 pm

Post by Mad_Haggis »

if(a%3 == 0 && a>3)

I forgot what back 2 back equals signs was?
BEER
User avatar
Philip
SG VIP
Posts: 11710
Joined: Sat May 08, 1999 5:00 am
Location: Jacksonville, Florida

Post by Philip »

Mad_Haggis, == is comparison operator, while single equal sign assigns value. i.e. a=3 would assign 3 to a, while a == 3 checks whether a equals 3. Then there are tripple comparison operators, like ===, !=== as well.

This line actually means: if "a" is divisible by 3 (if when we divide it by 3 the remainder is zero), and if "a" is greater than 3 ...
Post Reply