Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Comment



Header file



" ; " after loop



Test expression



Iterative statement




In a integer, count digits,sum of digits,reverse the integer and print even and odd digits of the integer



// AHF C PROGRAM SOLVING

//solving here basic type of programming problem

#include<stdio.h> #include<math.h> #define pf printf int main() { int n,temp,sum_of_digits=0,rev=0; int positive=0,negative=0,zero=0,total; pf("\nEnter any number: "); scanf("%d",&n); while(n!=0) { temp=n%10; rev=rev*10+temp; //pf("\n%d",temp); sum_of_digits+=temp; { if(temp%2==0) pf("\n%d is even number.",temp); else pf("\n%d is odd number.",temp); } { if(temp>0) positive++; else if(temp<0) negative++; else zero++; } total=positive+negative+zero; n/=10; } pf("\nThe reverse number of the integer is: %d",rev); pf("\nSUMMATION OF EVERY DIGITS= %d",sum_of_digits); pf("\ncount of digits in integer= %d",total); return 0; }
OUTPUT:


© 2018 - All rights reserved