Write a C program accepts N integers and prints the integers until 10 encounters. Note: The first integer is always not equal to 10.
Answers
Answered by
3
Answer:
#include<stdio.h>
int main(void)
{
int i, n, *ptr;
printf("Enter number of elements: ");
scanf("%d", &n);
ptr = (int*) malloc(n * sizeof(int));
// if memory cannot be allocated
if(ptr == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter elements: ");
for(i = 0; i < n; ++i)
{
scanf("%d", ptr + i);
if(*ptr == 10)
{
printf("First input can not be 10");
break;
}
}
printf("\nElements are: ");
for(i = 0; i < n; ++i)
{
printff("%d\t", ptr + i);
if(*(ptr+i)== 10)
break;
}
return 0;
}
Similar questions