In this page we have shared various types of c programs on various topics like loops,switch case,if-else statement,arrays,strings,pointer,functions,recursion etc.
This page consists of programs from basic c programs to high level c programs.
Search This Blog
Wednesday, June 26, 2019
Write a program in c to calculate the sum of digits.
#include<stdio.h> int main() { int num,r,sum=0; printf("Enter a number\n"); scanf("%d",&num); while(num>0) { r=num%10; sum=sum+r; num=num/10; } printf("Sum of digits=%d",sum); return 0; }
No comments:
Post a Comment