0% found this document useful (0 votes)
4 views8 pages

C Programming Projects on Numbers

The document contains a series of C programming code snippets that demonstrate various mathematical concepts, including checking for perfect numbers, strong numbers, palindromes, Armstrong numbers, and generating prime numbers. It also includes functionality for converting decimal numbers to binary and printing multiplication tables. Additionally, it serves as a semi-final programming project aimed at enhancing students' programming skills.

Uploaded by

billyjoetiro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

C Programming Projects on Numbers

The document contains a series of C programming code snippets that demonstrate various mathematical concepts, including checking for perfect numbers, strong numbers, palindromes, Armstrong numbers, and generating prime numbers. It also includes functionality for converting decimal numbers to binary and printing multiplication tables. Additionally, it serves as a semi-final programming project aimed at enhancing students' programming skills.

Uploaded by

billyjoetiro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CODE


Number 1:​

#include <stdio.h>

int main () {

int inp, dvs;


char cond;

do {

dvs = 0;

printf ("Please enter a number: ");


scanf ("%d", &inp);

for (int x = 1; x < inp; x++) {


if (inp % x == 0) {
dvs += x;
}

}
if (dvs == inp)
printf ("The number %d is a perfect number!", inp);

else
printf ("The number %d is not a perfect number!", inp);

printf ("\nPress any key to continue [n or N-to stop]: ");


scanf (" %c", &cond);

}while (cond != 'n' && cond != 'N');

return 0;
}​

Number 2:​

#include <stdio.h>

int main() {
int num, tmp, dgt, fct, sum;
char cond;

do {
printf("Enter a number: ");
scanf("%d", &num);

tmp = num;
sum = 0;

while (tmp > 0) {


dgt = tmp % 10;
tmp /= 10;

fct = 1;
for (int x = 1; x <= dgt; x++) {
fct *= x;
}

sum += fct;
}

if (sum == num)
printf("%d is a Strong number!", num);
else
printf("%d is not a Strong number!", num);

printf("\nPress any key to continue [n-to stop]: ");


scanf(" %c", &cond);

} while (cond != 'n' && cond != 'N');

return 0;
}

Number 3:​

#include <stdio.h>

int main () {

int rem, num, out;


char cond;

do {

printf ("Palindromic numbers between 1 and 1000: ");

rem = 0;
out = 0;

for (int x = 1; x <= 1000; x++) {


num = x;
out = 0;
while (num != 0) {
rem = num % 10;
num /= 10;

out = out * 10 + rem;

}
if (out == x) {
printf (" %d, ", x);
}
}
printf("\nPress any key to continue (press n or N to stop): ");
scanf (" %c", &cond);
} while (cond != 'n' && cond != 'N');

return 0;
}​

Number 4:​

#include <stdio.h>
#include <math.h>
int main() {

int num, val, dgt, sum, expo;


char cond;

do {
printf("Input number: ");
scanf("%d", &num);

val = num;
sum = 0;
expo = 0;

int temp = val;


while (temp > 0) {
temp /= 10;
expo++;
}

val = num;
while (val > 0) {
dgt = val % 10;
sum += pow(dgt, expo);
val /= 10;
}

if (sum == num)
printf("%d is an Armstrong number!", num);
else
printf("%d is not an Armstrong number!", num);

printf("\nPress any key to continue (Press n or N to stop): ");


scanf(" %c", &cond);

} while (cond != 'n' && cond != 'N');

return 0;
}​

Number 5:​

#include <stdio.h>

int main () {

int input, rem, num, out;


char cond;

do {

printf ("Please input number: ");


scanf ("%d", &input);

num = input;
rem = 0;
out = 0;

while (num != 0) {
rem = num % 10;
num /= 10;
out = out * 10 + rem;
}

if (out == input) {
printf ("%d is a palindrome!", input);
}
else
printf ("%d is not a palindrome!", input);

printf("\nPress any key to continue (press n or N to stop): ");


scanf (" %c", &cond);
} while (cond != 'n' && cond != 'N');

return 0;
}​

Number 6:​

#include <stdio.h>

int main() {

int n;
float sum;
char cond;

do {

printf("Please Enter n: ");


scanf("%d", &n);

sum = 0;

for (int x = 1; x <= n; x++) {


sum += 1.0 / x;
}

printf("Sum = %.6f", sum);

printf("\nPress any key to continue (press n or N to stop): ");


scanf(" %c", &cond);

} while (cond != 'n' && cond != 'N');

return 0;
}​

Number 7:​

#include <stdio.h>

int main () {

int num, set, count;


char cond;

do {
num = 0;
count = 0;

printf("Enter Limit of numbers: ");


scanf ("%d", &num);
printf ("Prime numbers: ");

for (int x = 2; x < num; x++) {


count = 0;
for (int y = 1; y <= x; y++) {
set = x % y;
if (set == 0) {
count++;
}
}
if (count == 2) {
printf ("%d ", x);
}

printf("\nPress any key to continue (press n or N to stop): ");


scanf (" %c", &cond);
} while (cond != 'n' && cond != 'N');

return 0;
}​

Number 8:​

#include <stdio.h>

int main() {

int num, temp, rem, bin = 0;


char cond;

do {

printf("Please enter decimal number: ");


scanf("%d", &num);

temp = num;
bin = 0;

while (temp > 0) {


rem = temp % 2;
temp = temp / 2;
bin = bin * 10 + rem;
}

int cor = 0;
while (bin > 0) {
rem = bin % 10;
bin /= 10;
cor = cor * 10 + rem;
}

printf("Binary = %d", cor);

printf("\nPress any key to continue (press n or N to stop): ");


scanf(" %c", &cond);

} while (cond != 'n' && cond != 'N');


return 0;
}​
Number 9:​

#include <stdio.h>

int main () {

int num, set;


char cond;

do {
num = 0;

printf("Enter Range: ");


scanf ("%d", &num);

for (int x = 1; x <= num; x++) {


set = 1;
printf ("Table of %d:\n", x);
for (int y = 1; y <= set; y++) {
printf ("%dx%d=%d\n", x, y, x*y);
set += 1;
if (set == 11) {
printf ("\n");
break;
}
}
}
printf("Press any key to continue (press n or N to stop): ");
scanf (" %c", &cond);
} while (cond != 'n' && cond != 'N');

return 0;
}​

Number 10:​

#include <stdio.h>

int main() {

int rows;
char cond;

do {

printf("Enter number of rows: ");


scanf("%d", &rows);

for (int x = 1; x <= rows; x++) {

for (int y = 1; y <= rows - x; y++) {


printf(" ");
}

for (int z = 1; z <= x; z++) {


printf("%d ", z);
}

for (int z = x - 1; z >= 1; z--) {


printf("%d ", z);
}
printf("\n");
}

printf("Press any key to continue (press n or N to stop): ");


scanf(" %c", &cond);

} while (cond != 'n' && cond != 'N');

return 0;
}









SEMI-FINAL ​
PROGRAMMING PROJECT​

Me when answering the project:​















This semi-final programming project lets the students better use


their acquired knowledge from all the programming discussions.
Testing and honing their skills with each objective, one problem
objective at a time.​









Submitted by:​
Billy Joe T. Tiro (BSIS DAY I - A)​


Submitted to:​
Ms. Janeth Sismer Ugang

You might also like