C program for Grade XI

1. C program to find the sum of individual digits of a number
#include<stdio.h> int main() { int i=1,n,r,sum=0,a; printf( " Enter value of n: "); scanf("%d",&n); a=n; while(n>0) { r=n%10; sum=sum+r; n=n/10; } printf(" Sum of digits of %d = %d ",a,sum); return 0; }
2. C program to find the sum of even digits of a number
#include<stdio.h> int main() { int i=1,n,r,sum=0,a; printf( " Enter value of n: "); scanf("%d",&n); a=n; while(n>0) { r=n%10; if(r%2==0) sum=sum+r; n=n/10; } printf(" Sum of even digits of %d = %d ",a,sum); return 0; }
3. C program to find the sum of odd digits of a number
#include<stdio.h> int main() { int i=1,n,r,sum=0,a; printf( " Enter value of n: "); scanf("%d",&n); a=n; while(n>0) { r=n%10; if(r%2==1) sum=sum+r; n=n/10; } printf(" Sum of odd digits of %d = %d ",a,sum); return 0; }
4. C program to find the sum of square of individual digits of a number
#include<stdio.h> int main() { int i=1,n,r,sum=0,a; printf( " Enter value of n: "); scanf("%d",&n); a=n; while(n>0) { r=n%10; sum=sum+r*r; n=n/10; } printf(" Sum of sqaure of digits of %d = %d ",a,sum); return 0; }