0

The following program should take 4 numbers but it takes 5 numbers and prints first 4 number entered. How to correct the problem???

#include<stdio.h>
#include<conio.h>

void main()
{ 
	int a1,a2,a3,a4;
	printf("Enter 4 numbers \n");
	scanf_s("%d %d %d %d ", &a1,&a2, &a3, &a4);
	printf("The 4 numbers entered are %d %d %d and %d",a1,a2, a3, a4);
	_getch();
}

Output

Enter 4 numbers
6
7
8
9
1
The four numbers entered are 6 7 8 and 9
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ahamed101
0

First: this is not C++ program!
Second: scanf_s - what kind of function is that? I don't know, maybe it exists, but I've heard only of scanf.
Third: solution is simple, remove blank space between last %d and "

scanf_s("%d %d %d %d", &a1,&a2, &a3, &a4);
// not (%d "), but (%d")

Fourth: Don't write void main() ! Write int main() instead.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.