Search This Blog

Labels

c codes (6) c++ codes (1)

Saturday, February 06, 2016

c program to print sum of the digits of the given number



c program to print sum of the digits of the given number

 In this program we have to given input a number and we have to find the sum of the digits of the given number and show the result in the output screen. This program is basically used for basic concept who are not known in the c programming.   

program code:-
#include<stdio.h>
int main()
 {
  int n,r,sum,m;
  printf("Enter a number :\n");
  scanf("%d",&n);
  m=n;
  sum=0;
  while(n>0)
    {
      r=n%10;
      sum=sum+r;
      n=n/10;
    }
printf("\n sum of digits of %d is %d ",m,sum);
return 0;
}

Output:-
cse@ubuntu:~$gcc sumdig.c - o sumdig
cse@ubuntu:~$./sumdig
Enter a number : 356

sum of digits of 356 is 14


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.  

C PROGRAM TO PRINT RADIUS AND VOLUME OF SPHERE



PROGRAM TO PRINT RADIUS AND VOLUME OF SPHERE

Program code:-

#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
 {
   float radius,sa,vol;
   printf("\nEnter radius of sphere:\n");
   scanf("%f",&radius);
   sa=4*PI*pow(radius,2);
   vol=(sa*PI*radius)/3;
   printf("\nvolume of sphere of %f radius is %f ",radius,vol);
   printf("\nsurface of sphere of %f radius is %f",radius,sa);
return 0;
}

Output:-

tsp@ubuntu:~$gccsphere.c - o sphere
tsp@ubuntu:~$./sphere
Enter radius:
2
volume of sphere of 2.000000 radius is 25.120001

surface area of sphere of 2.000000 radius is 50.240002   



In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Pages

Powered By Blogger