Basic C Programming Solve - Input output
SOLVED BY
Md. Masudur Rahman
Department of Textile Engineering
4th Batch
National Institute of Textile Engineering and Research (NITER)
masudbdasia@gmail.com
#Problem List:
- Write a program that prints your name.
- Write a program that read and display any character.
- Write a program that prints the value of n.
- Write a program that read and display an integer number.
- Write a program that read and display floating point number.
- Write a program that read and display double number.
- Write a program that read and display long number.
- Write a program that read and ASCII value and display equivalent character and vice-versa.
- Write a program that read any lower case character and display in upper case and vice-versa
#Introduction:
C programming has several in-build library functions to perform input and output tasks.
Two commonly used functions for I/O (Input/Output) are printf() and scanf().
The scanf() function reads formatted input from standard input (keyboard) whereas the printf() function sends formatted output to the standard output (screen).
#How this program works?
- All valid C program must contain the main() function. The code execution begins from the start of main() function.
- The printf() is a library function to send formatted output to the screen. The printf() function is declared in "stdio.h" header file.
- Here, stdio.h is a header file (standard input output header file) and #include is a preprocessor directive to paste the code from the header file when necessary. When the compiler encounters printf() function and doesn't find stdio.h header file, compiler shows error.
- The return 0; statement is the "Exit status" of the program. In simple terms, program ends.
Write a program that prints your name.
#include<stdio.h>
void main ()
{
printf("My Name Is Masud");
return 0;
}
2) Write a program that read and display any character.
#include<stdio.h>
#include<stdio.h>
void main ()
{
char n;
printf("Enter any character:");
scanf("%c",&n);
printf("The character is : %c",n);
}
3) Write a program that prints the value of n.
#include<stdio.h>
void main ()
{
int n;
n = 5;
printf("The value of n is %d", n);
}
4) Write a program that read and display an integer number.
#include<stdio.h>
int main ()
{
int n;
printf("Enter any integer number:");
scanf("%d", &n);
printf("The integer number is %d", n);
}
5) Write a program that read and display floating
point number.
#include<stdio.h>
void main ()
{
float n;
printf("Enter any floating point number:");
scanf("%f", &n);
printf("The floating point number is %f", n);
}
6) Write a program that read and display double number.
#include<stdio.h>
void main ()
{
double n;
printf("Enter any double number :");
scanf("%lf", &n);
printf("The duble number is %lf", n);
}
7) Write a program that read and display long number.
#include<stdio.h>
void main ()
{
long n;
printf("Enter any long number :");
scanf("%d", &n);
printf("The long number is %d", n);
}
8.Write a program that read and ASCII value and display equivalent character and vice-versa.
(8) (A)Write a program that read and ASCII value and display equivalent character.
#include<stdio.h>
int main ()
{
int n;
printf("Enter any ASCII value:");
scanf("%d",&n);
printf("The equivalent character is %c",n);
}
(8) (B) Write a program that read character and display equivalent ASCII value.
#include<stdio.h>
int main ()
{
char n;
printf("Enter any character :");
scanf("%c",&n);
printf("The equivalent ASCII value is %d",n);
}
9.Write a program that read any lower case character and display in upper case and vice-versa.
(9) (A) Write a program that read any lower case character and display in upper case.
#include<stdio.h>
void main ()
{
char n;
printf("Enter any lower case character:");
scanf("%c", &n);
printf("The equivalent upper cases is %c", n-32);
}
(9) (B) Write a program that read any upper case character and display in lower case.
#include<stdio.h>
void main ()
{
char n;
printf("Enter any upper case character:");
scanf("%c", &n);
printf("The equivalent lower case is %c", n+32);
}
4) Write a program that read and display an integer number.
#include<stdio.h>
int main ()
{
int n;
printf("Enter any integer number:");
scanf("%d", &n);
printf("The integer number is %d", n);
}
5) Write a program that read and display floating point number.
#include<stdio.h>
void main ()
{
float n;
printf("Enter any floating point number:");
scanf("%f", &n);
printf("The floating point number is %f", n);
}
6) Write a program that read and display double number.
#include<stdio.h>void main ()
{
double n;
printf("Enter any double number :");
scanf("%lf", &n);
printf("The duble number is %lf", n);
}
7) Write a program that read and display long number.
#include<stdio.h>
void main ()
{
long n;
printf("Enter any long number :");
scanf("%d", &n);
printf("The long number is %d", n);
}
8.Write a program that read and ASCII value and display equivalent character and vice-versa.
(8) (A)Write a program that read and ASCII value and display equivalent character.
#include<stdio.h>
int main ()
{
int n;
printf("Enter any ASCII value:");
scanf("%d",&n);
printf("The equivalent character is %c",n);
}
(8) (B) Write a program that read character and display equivalent ASCII value.
#include<stdio.h>
int main ()
{
char n;
printf("Enter any character :");
scanf("%c",&n);
printf("The equivalent ASCII value is %d",n);
}
9.Write a program that read any lower case character and display in upper case and vice-versa.
(9) (A) Write a program that read any lower case character and display in upper case.
#include<stdio.h>
void main ()
{
char n;
printf("Enter any lower case character:");
scanf("%c", &n);
printf("The equivalent upper cases is %c", n-32);
}
(9) (B) Write a program that read any upper case character and display in lower case.
#include<stdio.h>
void main ()
{
char n;
printf("Enter any upper case character:");
scanf("%c", &n);
printf("The equivalent lower case is %c", n+32);
}
void main ()
{
char n;
printf("Enter any upper case character:");
scanf("%c", &n);
printf("The equivalent lower case is %c", n+32);
}
ConversionConversion EmoticonEmoticon