Computer Science, asked by Has007, 1 year ago

write a C program for sum of digits.

Answers

Answered by garywalter1221
1

#include <stdio.h>

 

int main()

{

int  t, sum = 0, remainder,n;

printf("Enter an integer :");

scanf("%d", &n);

 

t = n;

  while (t != 0)

{

remainder = t % 10;

sum= sum + remainder;

t  = t / 10;

}

 printf("Sum of digits of %d = %d\n", n, sum);

 return 0;

}



Hope this will help u


Has007: Thanks bro
garywalter1221: u r welcome
Answered by Soñador
0

Answer:

#include<iostream.h>

#include<conio.h>

voud main()

{

clrscr();

int a, b,sum;

cout<<"\nEnter first number";

cin>>a;

cout<<"\nEnter second number";

cin>>b;

sum=a+b;

cout<<"\nSum of digits is "<<sum;

getch();

}

Similar questions