w3resource logo


C Programming Exercises

C Exercises: Add two numbers

C Pointer : Exercise-4 with Solution

Write a program in C to add two numbers using pointers.

Sample Solution:

C Code:

#include <stdio.h>
int main()
   int fno, sno, *ptr, *qtr, sum;
   printf("\n\n Pointer : Add two numbers :\n"); 
   printf(" Input the first number : ");
   scanf("%d", &fno);
   printf(" Input the second  number : ");
   scanf("%d", &sno);   
   ptr = &fno;
   qtr = &sno;
   sum = *ptr + *qtr;
   printf(" The sum of the entered numbers is : %d\n\n",sum);
   return 0;

Sample Output:

 Pointer : Add two numbers :                                                                                  
 Input the first number : 5                                                                                   
 Input the second  number : 6                                                                                 
 The sum of the entered numbers is : 11


Flowchart: Add two numbers

C Programming Code Editor:

Improve this sample solution and post your code through Disqus.