C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Point Out Errors (Q.No. 2)
2.
Point out the error in the program?
#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
Discussion:
23 comments Page 3 of 3.
Pooja said:
5 years ago
I couldn't get the answer can you explain properly?
(1)
Rutuja Revadekar said:
4 years ago
I thought the error was in printf statement.
Mishat said:
4 years ago
@All.
#include<stdio.h>
int main()
{
char ch;
int i;
scanf("\n%d", &i);
scanf("\n%c", &ch);
printf("%d %c", i, ch);
getch();
return 0;
}
In the case of integer it is %d and for character it ic %c.
#include<stdio.h>
int main()
{
char ch;
int i;
scanf("\n%d", &i);
scanf("\n%c", &ch);
printf("%d %c", i, ch);
getch();
return 0;
}
In the case of integer it is %d and for character it ic %c.
(2)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers