Thursday, April 25, 2019

SUM OF 6 NUMBERS

  • Problem Description

    Print the sum of 6 numbers using array and pointers
  • Test Case 1

    Input (stdin)
    1 2 3 4 5 6

    Expected Output
    21
  • Test Case 2

    Input (stdin)
    1 1 1 2 2 2

    Expected Output
    9
Solution

#include<stdio.h>
int main() {
   int numArray[10];
   int i, sum = 0;
   int *ptr;
 
   for (i = 0; i < 10; i++)
      scanf("%d", &numArray[i]);
 
   ptr = numArray;
 
   for (i = 0; i < 6; i++) {
      sum = sum + *ptr;
      ptr++;
   }
 
   printf("%d", sum);
  return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...