
Call 1800-123-2003
"Smartindia is the best online tool for school students." Ms Deepa Chandran, Principal Anchal
"Smartindia is one of the best supplementary education tool for school students." Ms Pooja, Principal
Write a C++ program to input a number and display all of its factors. (For example, if the input is 28, the output should be 1, 2, 4, 7, 14, 28). |
#include<iostream.h> #include<stdio.h> int main() { int n,i; cout<<"Enter a positive integer: "<<endl; cin>>n; cout<<"Factors of <<n<<"are :"<<endl; for(i=1;i<=n;++i) { if(n%i==0) printf("%d ",i); } return 0; } |