PPSC EXERCISE-1

 

EXERCISE-1

1. Write a C program to print a block F using hash (#), where the F has a height of six characters and width of five and four characters.
SOURCE CODE:
#include<stdio.h>
int main(){
    printf("#####\n");
    printf("#\n");
    printf("#\n");
    printf("####\n");
    printf("#\n");
    printf("#\n");
    return 0;
}
OUTPUT:
#####
#
#
####
#
#

2. Write a C program to compute the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches.
SOURCE CODE:
#include<stdio.h>
int main(){
    float length, width, area, perimeter;
    printf("Enter the length and width of the rectangle : ");
    scanf("%f%f",&length,&width);
    area = length*width;
    perimeter = 2*(length+width);
    printf("Area of rectangle : %f square inches\n",area);
    printf("Perimeter of rectangle : %f inches\n",perimeter);
    return 0;
}
OUTPUT:
Enter the length and width of the rectangle : 7 5
Area of rectangle : 35.000000 square inches
Perimeter of rectangle : 24.000000 inches

3. Write a C program to display multiple variables.
SOURCE CODE:
#include<stdio.h>
int main(){
int i;
short int si;
long int li;
float f;
double d;
long double ld;
char c;
printf("Enter int, short int and long int values : ");
scanf("%d%hd%ld",&i,&si,&li);
printf("Enter float, double and long double values : ");
scanf("%f%lf%Lf",&f,&d,&ld);
printf("Enter a character : ");
scanf(" %c",&c);
printf("Given int value : %d\n",i);
printf("Given short int value : %hd\n",si);
printf("Given long int value : %ld\n",li);
printf("Given float value : %f\n",f);
printf("Given double value : %lf\n",d);
printf("Given long double value : %Lf\n",ld);
printf("Given character : %c\n",c);
return 0;
}
OUTPUT:
Enter int, short int and long int values : 12345 123 1234567
Enter float, double and long double values : 1.2 3.14 9.334
Enter a character : G
Given int value : 12345
Given short int value : 123
Given long int value : 1234567
Given float value : 1.200000
Given double value : 3.140000
Given long double value : 9.334000
Given character : G

No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...