w3resource logo


C Programming Exercises

C Basic Declarations and Expressions : Exercises, Practice, Solution

Secondary Nav

C Basic Declarations and Expressions [7 exercises with solution]

1. Write a C program to print your name, date of birth. and mobile number. Go to the editor
Expected Output :

Name   : Alexandra Abramov  
DOB    : July 14, 1975  
Mobile : 99-9999999999

Click me to see the solution

2. 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. Go to the editor
Expected Output :

######
#
#
#####
#
#
#

Click me to see the solution

3. Write a C program to print a big 'C'. Go to the editor
Expected Output :

    ######
  ##      ##
 #
 #
 #
 #
 #
  ##      ##
    ######

Click me to see the solution

4. Write a C program to print the following characters in a reverse way. Go to the editor
Test Characters : 'X', 'M', 'L'
Expected Output :
The reverse of XML is LMX
Click me to see the solution

5. Write a C program to compute the perimeter and area of a rectangle with a height of 7 inches. and width of 5 inches. Go to the editor
Expected Output :
Perimeter of the rectangle = 24 inches
Area of the rectangle = 35 square inches
Click me to see the solution

6. Write a C program to display multiple variables. Go to the editor
Sample Variables :
a+ c, x + c,dx + x, ((int) dx) + ax, a + x, s + b, ax + b, s + c, ax + c, ax + ux
Declaration :
int a = 125, b = 12345;
long ax = 1234567890;
short s = 4043;
float x = 2.13459;
double dx = 1.1415927;
char c = 'W';
unsigned long ux = 2541567890;
Click me to see the solution

7. Write a C program to convert specified days into years, weeks and days. Go to the editor
Note: Ignore leap year.

Test Data :
Number of days : 1329
Expected Output :
Years: 3
Weeks: 33
Days: 3
Click me to see the solution

Go Top

Practice online

#include <stdio.h> 
int main()  
 {
  }

List of Exercises with Solutions :



Join our Question Answer community to learn and share your programming knowledge.