Computer Science, asked by sahanagh3238, 1 year ago

Write a 'C' program to calculate sum of digits of a number.

Answers

Answered by Anonymous
1

Answer:

C

#include <stdio.h>

#include <conio.h>

void main(){

int n,i,s;

printf("Enter no.");

scanf("%d",&n);

while(n>0){

i = n%10;

s = s+i;

n = n/10;

}

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

}

C++

#include <iostream>

using namespace std;

void main(){

int n,i,s;

cout<<"Enter no.";

cin>>n;

while(n>0){

i = n%10;

s = s+i;

n = n/10;

}

cout<<"Sem of digits",n;

}

Answered by shiva9597
0

Explanation:

Hope this helps you.

Plz Mark me as the brainest

Attachments:
Similar questions