
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Find the sum of first and last digit for a number using C language
The sum of first and last digit for a number can be calculated if we use the below mentioned algorithm in C programming language.
Algorithm
Refer an algorithm given herewith −
START Step 1: Declare no, sum variables of type int Step 2: Read a number at runtime Step 3: Compute sum=no%10 Step 4: While loop no>9 No=no/10 Step 5: Compute sum=sum+no; Step 6: Print sum STOP
Example
Following is the C program to find the sum of first and last digit for a number −
#include <stdio.h> int main(){ unsigned int no,sum; printf("enter any number:"); scanf("%u",&no); sum=no%10; while(no>9){ no=no/10; } sum=sum+no; printf("sum of first and last digit is:%d",sum); return 0; }
Output
You will see the following output −
enter any number:1242353467 sum of first and last digit is:8
Following is a C program to calculate sum all elements in an array −
Example
#include<stdio.h> void main(){ //Declaring the array - run time// int array[5]={10,20,30,40,50}; int i,sum=0,product=1; //Reading elements into the array// //For loop// for(i=0;i<5;i++){ //Calculating sum and product, printing output// sum=sum+array[i]; } //Displaying sum // printf("Sum of elements in the array is : %d
",sum); }
Output
You will see the following output −
Sum of elements in the array is : 150
- Related Articles
- Finding sum of first and last digit using divide and modulo operator in C language
- Sum of the first and last digit of a number in PL/SQL
- Count of Numbers in Range where first digit is equal to last digit of the number in C++
- Find Last Digit of a^b for Large Numbers in C++
- Check if the first and last digit of the smallest number forms a prime in Python
- Find the sum of the largest 5 -digit number and the smallest 6 -digit number.
- C++ program to find first digit in factorial of a number
- Program to find last digit of n’th Fibonnaci Number in C++
- Find the frequency of a digit in a number using C++.
- C program to find sum of digits of a five digit number
- Find 2’c complements for given binary number using C language
- C++ program to find sum of digits of a number until sum becomes single digit
- First digit in factorial of a number in C++
- Find the unit place digit of sum of N factorials using C++.
- The units digit of a two digit number is 3 and seven times the sum of the digits is the number itself. Find the number.

Advertisements