-->

program to input a string and display it

// program to input string and display it
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
printf(“enter a string\n”);
gets(a); // we can also use scanf("%[^\n]",a);
puts(a); // we can also use printf("the string =%s",a);
getch();
}

note:
1)gets() function is used to input a string and
puts() is used to display that string.
may be with space or without space.
2) If we use scanf("%[^\n]",a) then it accepts space for a string but if we use scanf("%s",a) then it does not accept string with space.so better to use gets or scanf("%[^\n",a);

program to input and display single character



// program to input single character and display it
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
printf(“enter a single character\n”);
scanf(“%c”,&a); // we can also use a=getchar()
printf(“the character=%c\n”,a); // we can also use putchar(a)
getch();
}

note:
getchar() function is only used to input a single character and
putchar() is only for one character display

program to convert paisa to rupees

// program to convert paisa to rupees
#include<stdio.h>
#include<conio.h>
void main()
{
float paisa;
float rupees;
printf(“enter amount of paisa\n”);
scanf(“%f”,&paisa);
rupees=paisa/100;
printf(“the area is=%f\n”,rupees);
getch();
}

program to get area of triangle using perimeter concept

// program to get area of triangle using perimeter concept
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
float s,area,peri;
printf(“enter sides of triangle\n”);
scanf(“%f%f%f”,&a,&b,&c);
s=a+b+c;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf(“the area is=%f\n”,area);
getch();
}

program to get area of square

// program to get area of square
#include<stdio.h>
#include<conio.h>
void main()
{
float length;
float area;
printf(“enter base and height of square\n”);
scanf(“%f”,&length);
area=length*length;
printf(“the area is=%f\n”,area);
getch();
}

program to get area of parallelogram

//program to get area of parallelogram
#include<stdio.h>
#include<conio.h>
void main()
{
float base,height;
float area;
printf(“enter base and height of parallelogram\n”);
scanf(“%f%f”,&base,&height);
area=base*height;
printf(“the area is=%f\n”,area);
getch();
}

program to get simple interest and amount

//program to get simple interest
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,t;
float interest,A;
printf("enter principal,rate of interest and time\n");
scanf("%f%f%f",&p,&r,&t);
interest=(p*t*r)/100;
A=p+interest;
printf("the interest gained is=%f\n",interest);
printf("the amount after interest=%f\n",A);
getch();
}