Input Output statement in C practice mode 2

0









Input/Output Statements 

4.1

Program to demonstrate the concept of putchar() function 

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
printf("Enter any character from the keyboard \n");
ch=getchar();
printf("Character you have entered is :\n ");
putchar(ch);
}
Output
Entered any character from the keyboard  g
character you have enterd is  g




4.2 

Program to demonstrate the concept of getchar() function

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
printf("Enter any character from the keyboard \n");
ch=getchar();
printf("\nCharacter you have entered is %c"ch);
getch();
}
Output
Entered any character from the keyboard  j
character you have enterd is  j



4.5 
Program to demonstrate the concept of gets() and puts() function

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char name[20],course[10];
printf("Enter your name\n");
gets(name);
printf("Enter your course in which you want to take admission \n");
gets(course);
printf("Data entered by you is :\n");
puts(name);
puts(course);
}
Output:
Enter your name
Gopal
Enter your course in which you want to take admission 
MCA
Data enterd by you is:
Gopal 
MCA



4.12 Program to find the compound interest.
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float p,r,t,ci;
printf("Enter your principal , rate and time");
scanf("%f%f%f",&p,&r,&t);
ci=p*(pow((1+r/100),t)-1);
printf("Compound interest is =%f",ci);
}
Output:
Enter your principal ,rate and time 
100
5
5
Compound interest is = 27.628157


Program 4.15 Program to convert character to ASCII code 
(American Standard Code for Information Interchange)

#include<conio.h>
#include<math.h>
void main()
{
char ch;
printf("Enter a character \n ");
ch=getchar();
printf("ASCII value :\n");
printf("%d",ch);
getch();
}
 
Output:

  Enter a character G
  ASCII value 71
  
Program 4.18 Program to input a string using gets() 
and display the string using puts() function .

#include<conio.h>
#include<math.h>
void main()
{
  char name[20],course[10],college[35];
  printf("Enter your name");
  gets(name);
   printf("In which class do you read");
  gets(course);
   printf("Enter name your college");
  gets(college);
  printf("you have entered ");
  puts(name);
  printf("\n");
  puts(course);
  printf("\n");
  puts(college);
  printf("\n");
  getch()
  }
  
Output:

  Enter your name Manisha
  In which class do you read? MCA
  Enter name of your college Doaba college
  You have Entered 
  Manisha 
  MCA
  Doaba college
  
4.20 Program to print the type of character entered from keyboard

  #include<conio.h>
#include<math.h>
#include<ctype.h>
void main()
{
char ch;
printf("Press any character from the keyword ");
ch=getchar();
if(islower(ch)!=0)
{
printf("it is a lower case charcter ");

  
  
  
  

1.1
Hello World Program 
Tags

Post a Comment

0Comments
Post a Comment (0)