Monday, June 18, 2012

To calculate the double of a given set of numbers using functions


/* Program to calculate the double of a given set of numbers using functions */

#include<stdio.h>

#include<conio.h>

/* Function Declaration */

void doubleThem(int a[10]);

void main()

{

  int mySet[10]={0,1,2,3,4,5,6,7,8,9};

  clrscr();

  doubleThem(mySet);    /* Function Call*/

  getch();

}

 

/* Function Definition */

void doubleThem(int a[10])

{

  int i;

  printf("\nThe given numbers are:");

  for(i=0;i<10;i++)

    printf("\t%d",a[i]);

  printf("\nThe double the numbers are:");

  for(i=0;i<10;i++)

  {

    a[i]=2 * a[i];

    printf("\t%d",a[i]);

  }

}

 

OUTPUT

 

The given numbers are:  0       1       2       3       4       5       6        7       8       9

The double the numbers are:     0       2       4       6       8       10       12      14      16      18

 

 

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.