write a 'c' program to sum the number of integer values

Answer Posted / vignesh1988i

here the program uses dynamic memory allocation concept instead of arraya......


#include<stdio.h>
#include<conio.h>
void main()
{
int *pointer,n,sum=0;
clrscr();
printf("enter no. of elements :");
scanf("%d",&n);
pointer=(int*)malloc(n*sizeof(int));
for(int i=0;i<n;i++)
{
scanf("%d",(pointer+i));
sum=sum+(*(pointer+i));
}
printf("the sum is :%d",sum);
getch();
}


thank u

Is This Answer Correct ?    11 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is bit rate & baud rate? plz give wave forms

1519


What is the value of uninitialized variable in c?

576


What is malloc and calloc?

574


printf(), scanf() these are a) library functions b) userdefined functions c) system functions d) they are not functions

636


What is || operator and how does it function in a program?

629






List some basic data types in c?

560


What is logical error?

605


What is the difference between abs() and fabs() functions?

607


Is there a way to compare two structure variables?

617


What is the purpose of realloc()?

672


What is the difference between declaring a variable and defining a variable?

724


what is use of malloc and calloc?

1384


Suggesting that there can be 62 seconds in a minute?

598


What is meant by 'bit masking'?

885


Explain what are multibyte characters?

629