Program for calculate sum of Factors of a given number

# include<stdio.h> #include<conio.h> main (  ) { int x, i = 1, sum = 0; printf (“enter a number”); scanf (“...

# include<stdio.h>
#include<conio.h>
main (  )
{
int x, i = 1, sum = 0;
printf (“enter a number”);
scanf (“%d”, &x);
while (i < = x)
{
 if (x % i = = 0)
 {
   sum = sum + i ;
   printf (“\n %d is a factor \n”, i);
  }
  i ++;
}          
printf (“\n sum of factors is % d”, sum);
getch();
}

Out put:

Enter a number 6
1 is a factor
2 is a factor
3 is a factor
6 is a factor

Related

Program for Matrix Addition and Subtraction

# include <stdio.h> #include<conio.h> main ( ) { int a[3][3],b[3][3],c[3][3],d[3][3],i,j; printf(“enter elements into matrix a”); for ( i = 0; i < 3; i + + ) for ( j = 0; j &l...

Program to Find Largest and Smallest numbers using Arrays

# include <stdio.h> #include<conio.h> main () { int a[10],i,big,small,n; printf (“enter the size of the array”); scanf (“%d, & n); printf (“enter elements in an array”); for ...

Write a program for Sorting of Numbers using Functions & Pointer?

#include<stdio.h> #include<conio.h> void sort(int *,int); void main() { int a[10], i, n; printf(“enter how many elements”); scanf(“%d”, &n); printf(“enter elements”); f...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item