You are on page 1of 6

Ans 1:

#include <stdio.h>

Int main() {

// Declare and initialize variables

Int numItems = 5;

Float taxRate = 0.07;

Char currencySymbol = ‘$’;

Double subtotal = 23.45;

// Calculate total amount after tax

Double totalAmount = subtotal * (1 + taxRate);

// Print the total bill

Printf(“Number of items: %d\n”, numItems);

Printf(“Tax rate: %.2f%%\n”, taxRate * 100);

Printf(“Currency symbol: %c\n”, currencySymbol);

Printf(“Subtotal: %.2lf %c\n”, subtotal, currencySymbol);

Printf(“Total amount after tax: %.2lf %c\n”, totalAmount, currencySymbol);

Return 0;

Ans 2:

#include <stdio.h>

Int main() {

// Declare and initialize variables

Int age = 25;

Float height = 1.75;


Char firstLetter = ‘R’;

Double weight = 65.5;

Long phoneNumber = 9876543210;

Short zipCode = 12345;

Unsigned numPets = 2;

Signed incomeExpDiff = -500;

// Print the values of variables

Printf(“Age: %d years\n”, age);

Printf(“Height: %.2f meters\n”, height);

Printf(“First letter of name: %c\n”, firstLetter);

Printf(“Weight: %.2lf kilograms\n”, weight);

Printf(“Phone number: %ld\n”, phoneNumber);

Printf(“Zip code: %hd\n”, zipCode);

Printf(“Number of pets: %u\n”, numPets);

Printf(“Income-Expenses difference: %d dollars\n”, incomeExpDiff);

Return 0;

Ans 3:

#include <stdio.h>

Int main() {

// Declare variables

Int originalNumber, reversedNumber = 0, remainder, temp;

// Input a five-digit number

Printf(“Enter a five-digit number: “);

Scanf(“%d”, &originalNumber);
// Store the original number in a temporary variable

Temp = originalNumber;

// Obtain the reversed number

While (temp != 0) {

Remainder = temp % 10;

reversedNumber = reversedNumber * 10 + remainder;

temp /= 10;

// Determine if the original and reversed numbers are equal

If (originalNumber == reversedNumber) {

Printf(“The original and reversed numbers are equal.\n”);

} else {

Printf(“The original and reversed numbers are not equal.\n”);

Return 0;

Ans 4:

#include <stdio.h>

Int main() {

// Declare variables

Float angle1, angle2, angle3;

// Input three angles of the triangle

Printf(“Enter the first angle of the triangle: “);


Scanf(“%f”, &angle1);

Printf(“Enter the second angle of the triangle: “);

Scanf(“%f”, &angle2);

Printf(“Enter the third angle of the triangle: “);

Scanf(“%f”, &angle3);

// Check if the triangle is valid

If (angle1 + angle2 + angle3 == 180) {

Printf(“The triangle is valid.\n”);

} else {

Printf(“The triangle is not valid. The sum of angles should be 180 degrees.\n”);

Return 0;

Ans 5:

#include <stdio.h>

Int main() {

// Declare variable

Char character;

// Input a character

Printf(“Enter a character: “);

Scanf(“ %c”, &character);

// Check if it is a lowercase character


If (character >= ‘a’ && character <= ‘z’) {

Printf(“It is a lowercase character.\n”);

// Check if it is an uppercase character

Else if (character >= ‘A’ && character <= ‘Z’) {

Printf(“It is an uppercase character.\n”);

} else {

Printf(“It is not a valid alphabetical character.\n”);

Return 0;

// Check if it is a vowel or a consonant

Switch (character) {

Case ‘a’:

Case ‘e’:

Case ‘I’:

Case ‘o’:

Case ‘u’:

Printf(“It is a vowel.\n”);

Break;

Default:

Printf(“It is a consonant.\n”);

Return 0;

Ans 6:

#include <stdio.h>
Int main() {

// Side length of each small equilateral triangle

Float smallTriangleSide = 2.0;

// Number of small triangles on one side of the large triangle

Int numSmallTriangles = 3;

// Calculate the perimeter of the large equilateral triangle

Float perimeter = numSmallTriangles * smallTriangleSide;

// Print the result

Printf(“The perimeter of the large equilateral triangle is: %.2f inches\n”, perimeter);

Return 0;

You might also like