c class- 1
c
Awasthi sir
8/25/202410 min read


















Keywords in C are reserved words that have special meaning to the compiler and cannot be used as identifiers (like variable names, function names, etc.). Here are some of the common keywords in C:
auto - Used to declare automatic variables.
break - Exits from a loop or a switch statement.
case - Used in switch statements to specify different cases.
char - Declares a character data type variable.
const - Declares a constant value that cannot be modified.
continue - Skips the remaining statements in the current iteration of a loop and proceeds with the next iteration.
default - Specifies the default block of code in a switch statement.
do - Used with while to create a do-while loop.
double - Declares a double-precision floating-point variable.
else - Specifies the block of code to be executed if the condition in an if statement is false.
enum - Defines a set of named integer constants.
extern - Declares a variable or function as external, meaning it is defined elsewhere.
float - Declares a floating-point variable.
for - Used to create a for loop.
goto - Transfers control to a labeled statement within a function.
if - Specifies a block of code to be executed if a condition is true.
int - Declares an integer variable.
long - Declares a long integer variable.
register - Suggests that the variable be stored in a CPU register.
return - Exits from a function and optionally returns a value.
short - Declares a short integer variable.
signed - Specifies that a variable can hold both positive and negative values.
sizeof - Returns the size of a variable or data type.
static - Declares a static variable or function.
struct - Defines a structure (a user-defined data type).
switch - Creates a switch statement for multi-way branching.
typedef - Defines a new data type name.
union - Defines a union (a user-defined data type that can store different data types in the same memory location).
unsigned - Specifies that a variable can hold only positive values.
void - Specifies that a function does not return a value.
volatile - Indicates that a variable's value may be changed by something outside the control of the program.
while - Creates a while loop.
In the C programming language, an identifier is a name used to identify a variable, function, array, or any other user-defined item in the program. Identifiers are fundamental components of any program because they are used to refer to the various data and functions within the code.
Characteristics of Identifiers:
Uniqueness: Each identifier must be unique within its scope. For example, you can't have two variables with the same name in the same function.
Case-Sensitive: In C, identifiers are case-sensitive. This means Variable, variable, and VARIABLE would all be considered different identifiers.
Allowed Characters: Identifiers can consist of letters (both uppercase and lowercase), digits, and underscores (_). However, they must begin with a letter or an underscore. They cannot begin with a digit.
Keywords Restriction: Identifiers cannot be the same as C's reserved keywords (e.g., int, return, for, etc.).






Question:
Write a C program that asks the user to enter their age and then prints out whether they are a "Child," "Teenager," "Adult," or "Senior" based on the following criteria:
Child: Age is less than 13.
Teenager: Age is between 13 and 19 (inclusive).
Adult: Age is between 20 and 64 (inclusive).
Senior: Age is 65 or older.
Question 1: Leap Year Checker
Write a C program that asks the user to enter a year and then checks if the year is a leap year or not. A year is a leap year if:
It is divisible by 4, and
It is not divisible by 100, unless
It is also divisible by 400.
Example:
If the user enters 2024, the program should print: "2024 is a leap year."
Question 2: Grade Calculator
Write a C program that asks the user to enter their marks for a subject and then prints out their grade based on the following criteria:
A: Marks are 90 or above.
B: Marks are between 80 and 89.
C: Marks are between 70 and 79.
D: Marks are between 60 and 69.
F: Marks are below 60.
Example:
If the user enters 85, the program should print: "You got a B."
Question 3: Even or Odd
Write a C program that asks the user to enter a number and checks whether it is even or odd.
Example:
If the user enters 7, the program should print: "7 is odd."
Question 4: Temperature Converter
Write a C program that converts a temperature given in Fahrenheit to Celsius and then categorizes it as "Cold," "Warm," or "Hot" based on the Celsius temperature:
Cold: Less than 10°C.
Warm: Between 10°C and 25°C (inclusive).
Hot: Greater than 25°C.
Formula to Convert Fahrenheit to Celsius:
Celsius=59×(Fahrenheit−32)text{Celsius} = frac{5}{9} times (text{Fahrenheit} - 32)Celsius=95×(Fahrenheit−32)
Example:
If the user enters 77 Fahrenheit, the program should print: "25°C, Warm."
Question 5: Basic Calculator
Write a C program that performs basic arithmetic operations (addition, subtraction, multiplication, and division). The program should ask the user to enter two numbers and an operator (+, -, *, /), and then it should display the result of the operation.
Example:
If the user enters 5, 3, and , the program should print: "5 3 = 15."
Question 6: Vowel or Consonant
Write a C program that asks the user to enter a single character and checks whether it is a vowel (a, e, i, o, u) or a consonant.
Example:
If the user enters a, the program should print: "a is a vowel."
Question 7: Number Classification
Write a C program that asks the user to enter an integer and then classifies it as:
Positive and even
Positive and odd
Negative and even
Negative and odd
Zero
Example:
If the user enters -4, the program should print: "-4 is negative and even."
Question 8: Triangle Type Checker
Write a C program that asks the user to enter the lengths of three sides of a triangle and then determines what type of triangle it is:
Equilateral: All three sides are equal.
Isosceles: Two sides are equal.
Scalene: No sides are equal.
Invalid: The sides do not form a valid triangle (hint: check the triangle inequality theorem).
Example:
If the user enters 3, 4, and 5, the program should print: "The triangle is Scalene."
Question 9: Simple Interest Calculator
Write a C program that asks the user to enter the principal amount, rate of interest, and time in years. Then calculate the simple interest and categorize the result:
Low Interest: Simple interest is less than 1000.
Moderate Interest: Simple interest is between 1000 and 5000.
High Interest: Simple interest is above 5000.
Formula:
Simple Interest=P×R×T100text{Simple Interest} = frac{P times R times T}{100}Simple Interest=100P×R×T
Example:
If the user enters 5000 (Principal), 5 (Rate), and 2 (Time), the program should print: "The interest is 500, Low Interest."
Question 10: Password Strength Checker
Write a C program that asks the user to enter a password and then checks its strength based on the following criteria:
Strong: The password is at least 8 characters long, contains at least one uppercase letter, one lowercase letter, one digit, and one special character.
Moderate: The password is at least 6 characters long and meets two of the criteria for a strong password.
Weak: The password does not meet the criteria for a moderate or strong password.
Example:
If the user enters P@ssw0rd, the program should print: "The password is Strong."
Question 11: BMI Calculator
Write a C program that calculates a user's Body Mass Index (BMI) and then classifies it as:
Underweight: BMI < 18.5
Normal weight: 18.5 ≤ BMI < 24.9
Overweight: 25 ≤ BMI < 29.9
Obesity: BMI ≥ 30
Formula:
BMI=weight in kg(height in meters)2text{BMI} = frac{text{weight in kg}}{text{(height in meters)}^2}BMI=(height in meters)2weight in kg
Example:
If the user enters 70 kg (weight) and 1.75 meters (height), the program should print: "Your BMI is 22.86, Normal weight."
Question 12: Shopping Discount Calculator
Write a C program that calculates the final price after applying a discount based on the total purchase amount:
No Discount: Purchase amount less than $100.
10% Discount: Purchase amount between $100 and $500.
20% Discount: Purchase amount between $500 and $1000.
30% Discount: Purchase amount greater than $1000.
Example:
If the user enters 750, the program should print: "Final price after discount: $600."
Question 13: Time of Day Greeting
Write a C program that asks the user to enter the current hour in 24-hour format (0-23) and then prints a greeting:
"Good Morning": 5 ≤ hour < 12
"Good Afternoon": 12 ≤ hour < 17
"Good Evening": 17 ≤ hour < 21
"Good Night": 21 ≤ hour < 24 or 0 ≤ hour < 5
Example:
If the user enters 14, the program should print: "Good Afternoon."
Question 14: Days in a Month
Write a C program that asks the user to enter a month (1-12) and a year, then determines how many days are in that month. Account for leap years in February.
Example:
If the user enters 2 and 2024, the program should print: "February 2024 has 29 days."
Question 15: ATM Withdrawal
Write a C program that simulates an ATM withdrawal. The user should enter the amount they wish to withdraw. The program should check if the amount is a multiple of 100 and does not exceed the account balance (assume a balance of $5000). Then, it should print the remaining balance after the withdrawal or an error message if the conditions are not met.
Example:
If the user enters 1500, the program should print: "Transaction successful. Remaining balance: $3500."








LOOPS




Write a C program to print all natural numbers from 1 to n. – using while loop
Write a C program to print all natural numbers in reverse (from n to 1). – using while loop
Write a C program to print all alphabets from a to z. – using while loop
Write a C program to print all even numbers between 1 to 100. – using while loop
Write a C program to find sum of all natural numbers between 1 to n.
Write a C program to find sum of all even numbers between 1 to n.
Write a C program to find sum of all odd numbers between 1 to n.
Write a C program to print multiplication table of any number.
Write a C program to find sum of first and last digit of a number.
Write a C program to swap first and last digits of a number.
Write a C program to calculate product of digits of a number.
Write a C program to check whether a number is palindrome or not.
Write a C program to find frequency of each digit in a given integer.
Write a C program to print all ASCII character with their values.
Write a C program to check whether a number is Prime number or not.
Write a C program to print all Prime numbers between 1 to n.
Write a C program to find sum of all prime numbers between 1 to n.
Write a C program to check whether a number is Armstrong number or not.
Write a C program to print all Armstrong numbers between 1 to n.
Write a C program to check whether a number is Perfect number or not.
Write a C program to print all Perfect numbers between 1 to n.
Write a C program to check whether a number is Strong number or not.
Write a C program to print all Strong numbers between 1 to n.
Write a C program to find one’s complement of a binary number.
Write a C program to find two’s complement of a binary number.
Write a C program to convert Binary to Decimal number system.
Write a C program to convert Binary to Hexadecimal number system.
Write a C program to convert Octal to Decimal number system.
Write a C program to convert Octal to Hexadecimal number system.
Write a C program to convert Decimal to Binary number system.
Write a C program to convert Decimal to Octal number system.
Write a C program to convert Decimal to Hexadecimal number system.
Write a C program to convert Hexadecimal to Binary number system.
Write a C program to convert Hexadecimal to Octal number system.
Write a C program to convert Hexadecimal to Decimal number system.
Star pattern programs – Write a C program to print the given star patterns.
Number pattern programs – Write a C program to print the given number patterns.


Array Questions
Write a C program that takes an array of integers from the user, finds the maximum number in the array, and prints it.
Write a C program to find the sum of all elements in an array entered by the user.
Write a C program that calculates and prints the average of numbers stored in an array.
Write a C program to find the smallest element in an array entered by the user.
Write a C program to reverse the elements of an array entered by the user.
Write a C program to count the number of even and odd numbers in an array entered by the user.



