Problem Description
There is a machine in a lab which is working not properly. It displays the alternative elements in a set of input. The lab instructor asked the students to write a C Program for this scenario. i.e. to Print the Alternate Elements in an ArrayTest Case 1
Input (stdin)5
21 8 41 13 15Expected Output21 41 15
Test Case 2
Input (stdin)9
2 8 4 1 3 6 8 11 38Expected Output2 4 3 8 38
Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n");
for(i=0;i<n;i++)
//printf("%d \t",a[i]);
printf("\n\t");
for(i=0;i<n;i=i+2)
printf("%d \t",a[i]);
return 0;
}
this program has some issues, pls check it
ReplyDelete