QN 1. if a five-digit number is input through the keyboard ,write a program to calculate the sum of digits. (hint: Use the modules operator '%').
solution:
Screenshot
SOURCE CODE
#include <iostream>
#include<conio.h>
using namespace std ;
int main()
{
int n;
int sum =0;
cout<<"Enter a 5 digit number : ";
cin >>n;
for(int i ; i<6; i++)
{
sum = sum + n%10;
n=n/10;
}
cout<<sum;
}
No comments:
Post a Comment