#include <stdio.h>
#include <conio.h>
main()
{
int num, sum = 0, rem;
printf("Enter a number\n");
scanf("%d",&num);
while( num != 0 )
{
rem = num % 10;
sum = sum + rem;
num = num / 10;
}
printf("Sum of digits of entered number = %d\n",sum);
getch();
return 0;
}
OUTPUT:
Enter a number
36
Sum of digits of entered number = 9
Sample C Program To Print The System Date.
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main()
{
struct date d;
getdate(&d);
printf("Current system date is %d / %d / %d", d.da_day, d.da_mon, d.da_year);
getch();
return 0;
}
OUTPUT:
Current system date is 26/7/2011
ALSO READ:
-- Program To Print First Ten(10) Natural Numbers.
-- Program To Print Fibonacci Series Upto 100.
-- Program To Check Whether A Number Is Prime Or Not.
-- Program To Compute The Reverse Of A Number.
-- Program To Print A Semicolon Without Using A Semicolon.
-- Program To Display Function Without Using The Main Function.
-- Program To Print Any Print Statement Without Using Semicolon.
-- Program To Display Its Own Source Code As Its Output.
-- Program To Swap Two Strings Using strcpy() Function.
-- Program to accept a string and print the reverse of the given string.
-- Program To Get IP Address.
-- Program To Accept An Integer & Reverse It.
-- Program To Convert Given Number Of Days To A Measure Of Time Given In Years, Weeks & Days.
-- Program To Illustrate The Concept Of Unions.
-- Program To Find The Size Of A Union.
... Back To C++ Programs Index
... Back To C++ FAQ's Index
... Back To C Programs Index
... Back To C FAQ's Index
... Back To HR Interview Index
Is d.da_day etc are inbuilt??
ReplyDeleteyes. the structure date is defined by c and it includes, da_day, da_mon, da_year and etc. see your compiler manual for the details of it.
ReplyDeleteThe date one is a new one for me. Thanks for it.
ReplyDelete