You are here:   HomeC Programming (Theory)Basic Of C Prog.Write a C program to read and write int value in console.
by Dinesh Thakur Category: Basic Of C Programming

The function getchar () reads a single character at a time, i.e., it gives access to a single character which may be manipulated. For instance, the character may be changed by a new character, a lowercase letter may be changed to an upper case letter or vice versa, or a character may be removed from the string, and so on. However, for reading the complete string you have to use a loop.

void main()
int a, b;
char ch;
printf("Add, Subtract, Multiply, or Divide?\n");
printf("Enter first letter: ");
ch = getchar();
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
printf("%d", a+b);
printf("%d", a-b);
printf("%d", a*b);
if(ch=='D' && b!=0)
printf("%d", a/b);
Add, Subtract, Multiply, or Divide?
Enter first letter: A
Enter a: 412
Enter b: 214

Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.

What's New and Popular

Popular Article