/* Write a program to find whether the given number is odd or even using conditional operator.*/ #include <stdio.h> void main() { int n; printf("Enter the number : "); scanf("%d",&n); printf("The given number is %s\n",(n%2==0)?"Even":"Odd"); getch(); }
/* Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.*/ #include <stdio.h> void main() { int num,den; printf("Enter the numerator : "); scanf("%d",&num); printf("Enter the denominator : "); scanf("%d",&den); do { num-=den; }while(num>=den); printf("The remainder is %d\n",num); getch(); }
/* Write a program to print the sum of the digits of the given number using while loop.*/ #include <stdio.h> void main() { int n,s=0; printf("Enter the number : "); scanf("%d",&n); while(n>0) { s+=n%10; n/=10; } printf("The sum of the digits is %d\n",s); getch(); }
Comments
Post a Comment