The question ask to Write a C program that reads an integer array with M elements (M is read from the user). The program will print the original array with 3 decimal places per value, then count the number of odds and evens in the given array.
I use Dev-c by the way
My code
Code:
#include<stdio.h>
void main(){
int M,i,even=0,odd=0;
int a[M];
float b[M];
printf("Input array size:");
scanf(" %d",&M);
for (i=0;i<M;i++){
printf("With a[%d]=",i);
scanf(" %d",&a);
}
printf("Original array:");
for (i=0;i<M;i++){
b[i]=(float)a;
printf(" %.3f",b);
}
}
The problem:if I input 4, the output is ok. But when I input 5 or more the output shows this:
Input array size:9
With a[0]=1
With a[1]=2 ... With a[8]=9
Original array: 1.000 2.000 3.000 4.000 0.000 0.000 7.000 8.000 9.000
What is wrong?