SAMPLE PROGRAMS:
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. And also to print a big 'C'.
2. Write a C program to print your name, date of birth. and mobile number.
3. Write a C program to compute the perimeter and area of a rectangle with a
height of 7 inches. and width of 5 inches.
4. Program to print cube of given number.
5. Write a C program that accepts two integers from the user and calculate the
product of the two integers.
6. Write a C program to integral quotient and remainder of a division.
7. Write a C program to return the absolute value of an integer.
8. Write a C program to return the absolute value of a long integer.
Solutions:
Program 01:
#include <stdio.h>
int main()
{
printf("######\n");
printf("#\n");
printf("#\n");
printf("#####\n");
printf("#\n");
printf("#\n");
printf("#\n");
return(0);
}
Program 02:
#include <stdio.h>
int main()
{
printf("Name : Alexandra Abramov\n");
printf("DOB : July 14, 1975\n");
printf("Mobile : 99-9999999999\n");
return(0);
}
Program 03:
#include <stdio.h>
/* height and width of a rectangle in inches */
int width;
int height;
int area;
int perimeter;
int main() {
height = 7;
width = 5;
perimeter = 2*(height + width);
printf("Perimeter of the rectangle = %d inches\n",
perimeter);
area = height * width;
printf("Area of the rectangle = %d square inches\n", area);
return(0);
}
Program 04:
#include<stdio.h>
int main(){
int number;
printf("enter a number:");
scanf("%d",&number);
printf("cube of number is:%d ",number*number*number);
return 0;
}
Program 05:
#include <stdio.h>
int main()
{
int x, y, result;
printf("\nInput the first integer: ");
scanf("%d", &x);
printf("\nInput the second integer: ");
scanf("%d", &y);
result = x * y;
printf("Product of the above two integers = %d\n", result);
}
Program 06:
#include<stdio.h>
#include<stdlib.h>
int main ()
{
long int n,d;
ldiv_t result;
printf("\n Input numerator : ");
scanf("%ld",&n);
printf(" Input denominator : ");
scanf("%ld",&d);
result = ldiv (n,d);
printf (" quotient = %ld, remainder = %ld.\n\
n",[Link],[Link]);
return 0;
}
Program 07:
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int num;
printf("\n Input a positive or negative number :");
scanf("%d",&num);
printf (" The absolute value of the given number is :
%d\n\n",abs(num));
return 0;
}
Program 08:
#include<stdio.h>
#include<stdlib.h>
int main ()
{
long int x,y;
printf("\n Input 1st number (positive or negative) :
");
scanf("%ld",&x);
printf(" Input 2nd number (positive or negative) :
");
scanf("%ld",&y);
printf (" The absolute value of 1st number is : %ld\
n",labs(x));
printf (" The absolute value of 2nd number is : %ld\n\
n",labs(y));
return 0;
}