Created
October 5, 2014 16:09
-
-
Save raydvard/95c27aa419f1da0c8cb0 to your computer and use it in GitHub Desktop.
Assignment-2 (Prime,even and odd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
/*==================Variable Declarations & Assignments========================*/ | |
int lowLimit, highLimit, low, high; | |
int countLines = 0, sum_ev = 0, sum_od = 0, sum_prm = 0; | |
int constant_prm; | |
/*=============================================================================*/ | |
// Standard I/O | |
printf("Enter the range of numbers to find prime, even and odd numbers >>"); | |
printf("\n\nEnter the lower range number : "); | |
scanf("%d", &low); | |
printf("Enter the higher range number : "); | |
scanf("%d", &high); | |
/////////////// | |
/*==================Prime Numbers Queries========================*/ | |
printf("\n#==================Prime Numbers========================#"); | |
for( lowLimit = low, highLimit = high; lowLimit <= highLimit; lowLimit++ ) | |
{ | |
for( constant_prm = 2; constant_prm <= lowLimit - 1; constant_prm++ ) | |
{ | |
if( lowLimit % constant_prm == 0 ) | |
{ | |
break; | |
} | |
} | |
if( constant_prm == lowLimit ) | |
{ | |
countLines++; | |
printf("\nPrime Number %d : %d", countLines, lowLimit); | |
sum_prm = sum_prm + lowLimit; | |
} | |
} | |
printf("\n\nTotal Prime Numbers Count is : %d", countLines); | |
printf("\nTotal Prime Numbers Summation is : %d", sum_prm); | |
/*=============================================================================*/ | |
/*==================Even Numbers Queries========================*/ | |
printf("\n#==================Even Numbers========================#"); | |
for( lowLimit = low, highLimit = high, countLines = 0; lowLimit <= highLimit; lowLimit++ ) | |
{ | |
if( lowLimit % 2 == 0 ) | |
{ | |
countLines++; | |
printf("\nEven Number %d : %d", countLines, lowLimit); | |
sum_ev = sum_ev + lowLimit; | |
} | |
} | |
printf("\n\nTotal Even Numbers Count is : %d", countLines); | |
printf("\nTotal Even Numbers Summation is : %d", sum_ev); | |
/*=============================================================================*/ | |
/*==================Odd Numbers Queries========================*/ | |
printf("\n#==================Odd Numbers========================#"); | |
for( lowLimit = low, highLimit = high, countLines = 0; lowLimit <= highLimit; lowLimit++ ) | |
{ | |
if( lowLimit % 2 > 0 ) | |
{ | |
countLines++; | |
printf("\nOdd Number %d : %d", countLines, lowLimit); | |
sum_od = sum_od + lowLimit; | |
} | |
} | |
printf("\n\nTotal Odd Numbers Count is : %d", countLines); | |
printf("\nTotal Odd Numbers Summation is : %d", sum_od); | |
/*=============================================================================*/ | |
printf("\n#=====================================================#"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment