Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

/*write a program to demonstrate the reading of Integers in different formats */

Program
main()
{
int a,b,c,x,y,z;
int p.q.r;
printf("Enter three integer numbers\n");
scanf("%d **d %d",&a,&b,&c);
printf("%d %d %d\n\n", a,b,c);
printf("Enter two 4-digit numbers\n");
scanf("%2d $4d",&x,&y);
printf("%d %d\n\n", x,y);
printf("Enter two integers\n");
scanf("%d %d", &a,&x);
printf("%d %d\n\n", a,x);
printf("Enter a nine digit number\n");
scanf("%3d 4d \3d",&p,&q,&r);
printf("%d %d %d\n\n",p,q,r);
printf("Enter two three digit numbers\n");
scanf("%d %d",&x,&y);
printf("%d %d",x,y);
}

/* Write a c Program to Read real numbers (in both decimal point and exponential
notation) */
main()
{
float x.y:
double p.q:
printf("Values of x and y:");
scanf("%f %e", &x, &y);
printf("\n");
printf("x = %f\n y= %f\n\n”,x,y);
printf("Values of p and q:");
scanf("%1f %1f", &p, &q);
printf("\n\np= %.121f\np = %.12e", p.q);
}
/*1. Find the output of the following program. */
Program
#include <stdio.h>
main()
{
int a, b;
printf("\n Enter two four digit numbers : ");
scanf("%2d %4d", &a, &b);
printf("\n The two numbers are : %d and %d", a, b);
return 0;
}
/*2. Write a program to demonstrate the use of printf statement to print values of
variables of different data types.*/
Program
#include <stdio.h>
main()
{
// Declare and initialize variables
int num = 7;
float amt = 123.45;
char code = 'A’;
double pi = 3.1415926536;
long int population_of_india = 10000000000;
char msg[] = "Hi";
// Print the values of variables
printf("\n NUM = %d \t AMT = %f \t CODE = %c \n PI = %e \t POPULATION OF
INDIA = %ld \n MESSAGE = %s", num, amt, code, pi, population_of_india, msg);
return 0;
}
/*3. Write a program to demonstrate the use of printf and scanf statements to read and
print values of variables of different data types. */ (Model Question Paper 2)
Program
#include <stdio.h>
main()
{
int num;
float amt;
char code;
double pi;
long int population_of_india;
char msg[10];
printf("\n Enter the value of num : ");
scanf("%d", &num);
printf("\n Enter the value of amt : ");
scanf("%f", &amt);
printf("\n Enter the value of pi : ");
scanf("%e", &pi);
printf("\n Enter the population of india : ");
scanf("%ld", &population_of_india);
printf("\n Enter the value of code : ");
scanf("%c", &code);
printf("\n Enter the message : ");
scanf("%s", msg);
printf("\n NUM = %d \n AMT = %f \n PI = %e \n POPULATION OF INDIA = %ld
\n CODE = %c \n MESSAGE = %s", num, amt, code, pi, population_of_india, msg);
return 0;
}
/*4. Write a program to calculate the area of a triangle using Hero’s formula.*/
Program
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
float a, b, c, area, S;
printf("\n Enter the lengths of the three sides of the triangle : ");
scanf("%f %f %f", &a, &b, &c);
S = ( a + b + c)/2; // sqrt is a mathematical function defined in math.h header file
area = sqrt(S*(S-a)*(S-b)*(S-c));
printf("\n Area = %f", area);
return 0;
}
/*5. Write a program to calculate the distance between two points. */
Program
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int x1, x2, y1, y2;
float distance;
printf("\n Enter the x and y coordinates of the first point : ");
scanf("%d %d", &x1, &y1);
printf("\n Enter the x and y coordinates of the second point :");
scanf("%d %d", &x2, &y2); // sqrt and pow are mathematical functions defined in math.h
header file
distance = sqrt(pow((x2-x1), 2)+pow((y2-y1), 2));
printf("\n Distance = %f", distance);
return 0;
}
/*write a program to Calculate simple interest */
Program
# include <stdio.h>
int main( )
{
int p, n ;
float r, si ;
p = 1000 ;
n=3;
r = 8.5 ;
/* formula for simple interest */
si = p * n * r / 100;
printf ( "%f\n" , si ) ;
return 0 ;
}

You might also like