April 07, 2021

Sum of 5 digit number using c++

 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

find the cube of the range given digits. || codeAj

Find the cube of the range given Digits. Source Code r= int ( input ( "enter the range of digit : " )) def number_conter (n): ...