Introduction
C is a general-purpose programming language used to build software, operating systems, embedded systems, and many other applications. It is also an excellent language for learning programming fundamentals because it teaches variables, data types, operators, conditions, loops, functions, arrays, pointers, and memory concepts. In this chapter, you will practice basic C programs so you can understand how C code works and build a strong foundation for the chapters ahead. Introduction to C – practice questions with solutions to help you understand the concepts.
Q1. Display Hello World in C
Problem Statement
Write a C program to display Hello, World! on the screen.
C Program
#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}
Sample Output
Hello, World!
Concepts Covered
- C program
main()functionprintf()return 0- Basic C syntax
Q2. Display Your Name
Problem Statement
Write a C program to display your name on the screen.
C Program
#include <stdio.h>
int main()
{
printf("My name is Rahul.");
return 0;
}
Sample Output
My name is Rahul.
Concepts Covered
printf()- Text output
- String literal
- Basic C syntax
Q3. Display Multiple Lines
Problem Statement
Write a C program to display your name, age, and city on separate lines.
C Program
#include <stdio.h>
int main()
{
printf("Name: Rahul\n");
printf("Age: 14\n");
printf("City: Delhi");
return 0;
}
Sample Output
Name: Rahul
Age: 14
City: Delhi
Concepts Covered
- Multiple
printf()statements \n- Output formatting
- Basic C program structure
Q4. Display a Simple Calculation
Problem Statement
Write a C program to display the sum of two numbers.
C Program
#include <stdio.h>
int main()
{
printf("Sum = %d", 10 + 20);
return 0;
}
Sample Output
Sum = 30
Concepts Covered
- Arithmetic expression
- Addition operator
printf()- Integer output
Q5. Display Different Types of Values
Problem Statement
Write a C program to display an integer, decimal number, and character.
C Program
#include <stdio.h>
int main()
{
printf("Age: %d\n", 14);
printf("Height: %.2f\n", 5.6);
printf("Grade: %c", 'A');
return 0;
}
Sample Output
Age: 14
Height: 5.60
Grade: A
Concepts Covered
- Integer value
- Floating-point value
- Character value
%d%f%c
Q6. Calculate the Area of a Rectangle
Problem Statement
Write a C program to calculate and display the area of a rectangle when the length is 10 and the width is 5.
C Program
#include <stdio.h>
int main()
{
int length = 10;
int width = 5;
int area;
area = length * width;
printf("Area of rectangle = %d", area);
return 0;
}
Sample Output
Area of rectangle = 50
Concepts Covered
- Variables
- Variable initialization
- Multiplication
- Arithmetic expression
- Assignment
Q7. Calculate the Average of Three Numbers
Problem Statement
Write a C program to calculate the average of three numbers: 10, 20, and 30.
C Program
#include <stdio.h>
int main()
{
int a = 10;
int b = 20;
int c = 30;
int average;
average = (a + b + c) / 3;
printf("Average = %d", average);
return 0;
}
Sample Output
Average = 20
Concepts Covered
- Variables
- Addition
- Division
- Arithmetic expression
- Integer calculation
Q8. Convert Celsius to Fahrenheit
Problem Statement
Write a C program to convert a temperature of 25°C into Fahrenheit.
Use the formula:
Fahrenheit = (Celsius × 9 / 5) + 32
C Program
#include <stdio.h>
int main()
{
float celsius = 25;
float fahrenheit;
fahrenheit = (celsius * 9 / 5) + 32;
printf("Temperature in Fahrenheit = %.2f", fahrenheit);
return 0;
}
Sample Output
Temperature in Fahrenheit = 77.00
Concepts Covered
float- Arithmetic operators
- Formula implementation
- Decimal output
- Variables
Q9. Calculate Simple Interest
Problem Statement
Write a C program to calculate simple interest when:
- Principal = 5000
- Rate = 5%
- Time = 2 years
Use the formula:
Simple Interest = (Principal × Rate × Time) / 100
C Program
#include <stdio.h>
int main()
{
float principal = 5000;
float rate = 5;
float time = 2;
float simpleInterest;
simpleInterest = (principal * rate * time) / 100;
printf("Simple Interest = %.2f", simpleInterest);
return 0;
}
Sample Output
Simple Interest = 500.00
Concepts Covered
float- Variables
- Mathematical formulas
- Multiplication
- Division
- Formatted output
Q10. Create a Basic Student Information Program
Problem Statement
Write a C program that stores and displays a student’s name, age, marks, and grade.
C Program
#include <stdio.h>
int main()
{
char name[] = "Rahul";
int age = 14;
float marks = 87.5;
char grade = 'A';
printf("Student Information\n");
printf("-------------------\n");
printf("Name: %s\n", name);
printf("Age: %d\n", age);
printf("Marks: %.1f\n", marks);
printf("Grade: %c", grade);
return 0;
}
Sample Output
Student Information
-------------------
Name: Rahul
Age: 14
Marks: 87.5
Grade: A
Concepts Covered
- Character array
- Integer
- Float
- Character
%s%d%f%c- Multiple variables
- Structured output
Key Takeaways
- C is a general-purpose programming language.
- Every C program normally starts execution from the
main()function in C. #include <stdio.h>provides standard input/output functions such asprintf() in c language.printf()in c language is used to display information on the screen.- C language statements generally end with a semicolon
;. - Variables are used to store values.
- C language supports different data types such as
int,float, andchar. - Arithmetic expressions can be used directly in C language.
\nmoves output to a new line.- C programs can be used to solve practical mathematical and logical problems.
- Every C language starts execution from the
main()function in C.
FAQs
1. What is C language?
C is a general-purpose programming language used to develop different types of software and to learn fundamental programming concepts.
2. Why should beginners learn C?
C provides a strong foundation in programming concepts such as variables, operators, conditions, loops, functions, arrays, pointers, and memory management.
3. What is the main() function in C?
main() is the function where execution of a standard C program begins.
4. What is printf() used for in C?
printf() is used to display text, numbers, characters, and other formatted information on the screen.
5. Why do C statements end with a semicolon?
The semicolon tells the compiler that a C statement has ended.
For example:
printf("Hello");
6. What is #include <stdio.h> in C?
It includes the Standard Input/Output header file, which provides declarations for functions such as printf() and scanf().
7. Is C difficult for beginners?
C can seem challenging initially because it introduces programming concepts at a relatively low level. Learning one concept at a time and solving practical programs regularly makes it much easier to understand.
Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.