22.(C) Finding Divisor problem from Toph
#include<stdio.h>
// Finding Divisors of given number
int main(){
int num,i,d;
scanf("%d",&num);
for(i=num;i<=num;i--) // here I have use i-- for printing the output in higher order
{
if(num%i==0){
d=num/i;
printf("Divisors are:%d\n",d);
}
}
return 0;
}
This problem can also be done in another way:
#include<stdio.h>
int main(){
int A,i;
scanf("%d",&A);
for(i=1;i<=A;i++)
{
if(A%i==0)
{
printf("%d\n",i);
}
}
return 0;
}
Comments
Post a Comment