Q: Is there any way to make this adding an infinite? So I tried to make this a infinite loop of input for user and adding it. But it just end at the end. Please help
#include <stdio.h>
#include <stdlib.h>

int SUM(int a)
{
  int sum = 0;
  while (a > 0) 
  {
    sum = sum + (a % 10);
    a = a / 10;
  }
  return sum;
}

int main()
{
  int x;
  printf("Enter an integer = ");

  scanf("%d", &x);

  SUM(x);

  printf("Sum digit = %d", SUM(x));
}


A: Just add an infinite loop inside your main function like that:
#include <stdio.h>
#include <stdlib.h>

int SUM(int a){
int sum=0;
while(a>0){
    sum =sum+(a%10);

    a=a/10;

}

return sum;
}

int main(){
    int x;
    char quit = 'n';
    do{
        printf("Enter an integer = ");

        scanf("%d", &x);

        printf("Sum digit = %d", SUM(x));

        //exiting option 
        printf("Quit the program? [y/n]");
        scanf(" %c",&quit);
    }while(quit !='y' && quit != 'Y');   
}

also, the line that contain the SUM(x) function before the printf is redundant.
EDIT: I inserted an option to quit the inifinite loop at the end of each iteration - if you dont want that option, just change it to while(1) and delete both of the printing and scanf commands before the end.

A: I think you are trying to implement the infinite loop so that the sum value retains and another sum value can be added to it.
Hope this code Helps!!
Otherwise kindly improve your question
#include <stdio.h>
#include <stdlib.h>
int SUM(int a)
{
        int sum=0;
        while(a>0)
        {
                sum =sum+(a%10);
                a=a/10;
        }
        return sum;
}

int main()
{
        int x,choice,result=0;
        while(1)
        {
                printf("**MENU**\n");
                printf("1. Perform Sum\n");
                printf("2. Result\n");
                printf("3. Exit\n");
                printf("Choose:");
                scanf("%d",&choice);
                switch(choice)
                {
                case 1:
                        printf("Enter an integer = ");
                        scanf("%d", &x);
                        result+=SUM(x);
                        break;
                case 2:
                        printf("Sum digit = %d\n", result);
                        break;
                case 3:
                        printf("Final Result = %d\n",result);
                        exit(0);
                default:
                        printf("Try Again!\n");
                }

        }
        return(0);
}

