Find ODD Numbers

Learn and Trouble Shoot Problems Related to C-Language here.

Find ODD Numbers

Unread postby rajeevmahura » Thu May 22, 2008 6:36 pm

#include<stdio.h>
#include<conio.h>
void main()
{
int s=0,i,n;
clrscr();
printf("Enter the limit");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
continue;
else
printf("\n%d",i);
s=s+i;
}
printf("\n%d",s);
getch();
}
--Regards--
Rajeev Mahura
Servers & Storage Professional
http://about.me/rajeevmahura
User avatar
rajeevmahura
 
Posts: 144
Joined: Tue May 20, 2008 5:22 pm
Location: Bangalore | New Delhi
Full Name: Rajeev Mahura
Date Of Birth: 15 Jan 1984
Address: New Delhi
Profession: DOEACC Trainer
DOEACC Center: DOEACC DELHI
Mobile No: 0

Re: Find ODD Numbers

Unread postby manojthesingham » Tue Sep 01, 2009 6:13 am

#include<stdio.h>
#include<conio.h>
int main(int argc,char**argv)
{
int x;
printf("Enter the Number to check odd or even : ");
scanf("%d",&x); /*& ampersand for referencing*/
printf("%s",(x&1)?"ODD":"EVEN");/*& and operator*/
getch();
return 0;
}
/* ODD & 1 = 1 */
/* EVEN & 1 = 0 */
/* . . . 16 8 4 2 1 */
/* ODD some 0 or 1 but 2^0 == 1 */
/* EVEN some 0 or 1 but 2^0 == 0 */
If world is running, then I am idle..
If I am idle, then the world is running
User avatar
manojthesingham
 
Posts: 15
Joined: Tue Sep 01, 2009 5:39 am
Location: Coimbatore,Tamilnadu
Full Name: manoj
Date Of Birth: 31 Jul 1989
Address: Coimbatore18Tamilnadu
Mobile No: 0


Return to C-Language

Who is online

Users browsing this forum: No registered users and 1 guest

cron