0% found this document useful (0 votes)
20 views9 pages

Programming C Language Assignment

programming language

Uploaded by

selyor60
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Programming C Language Assignment

programming language

Uploaded by

selyor60
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming Practice Assignment Solutions

Student : Musaev Abdusamadjon Umidjon ugli

Student ID: 202420033

Major: AI (Computer Science)

Task 1: Decimal to Octal and Hexadecimal Conversion


Create a program that takes a decimal number as input and outputs its equivalent in octal
and hexadecimal formats.

#include <stdio.h>

int main() {
int decimalNumber;

printf("Please enter a decimal number: ");


scanf("%d", &decimalNumber);

printf("Hexadecimal number: 0x%X\n", decimalNumber);


printf("Octal number: 0%o\n", decimalNumber);
return 0;
}

Task 2: Display Special Characters and Bell Sound


Create a program that displays special characters and a bell sound.

#include <stdio.h>

int main() {
printf("\a\"Hello\", 'A' \\
");
return 0;
}

Task 3: ASCII Code for Input Alphabet


Write a program that takes an alphabet as input and outputs its ASCII code.
#include <stdio.h>

int main() {
char alphabet;

printf("Input an alphabet from the keyboard: ");


scanf(" %c", &alphabet);

printf("ASCII code in decimal: %d\n", alphabet);

return 0;
}

Task 4: Calculate BMI


Calculate Body Mass Index (BMI) given weight and height.
#include <stdio.h>

int main() {
double weight, height, bmi;

printf("Enter the weight(kg): ");


scanf("%lf", &weight);

printf("Enter the height(m): ");


scanf("%lf", &height);

bmi = weight / (height * height);

printf("Your BMI is %.2lf\n", bmi);

return 0;
}

Task 5: Convert Small Letter to Capital Letter


Convert a lowercase letter to uppercase.
#include <stdio.h>

int main() {
char smallLetter, capitalLetter;

printf("Enter a small letter: ");


scanf(" %c", &smallLetter);

capitalLetter = smallLetter - ('a' - 'A');

printf("The capital letter of %c is %c\n", smallLetter, capitalLetter);

return 0;
}

Task 6: Swap Two Integers


Swap two integers and display the result.
#include <stdio.h>

int main() {
int a, b, temp;

printf("Enter two integers: ");


scanf("%d %d", &a, &b);

printf("a = %d, b = %d\n", a, b);

temp = a;
a = b;
b = temp;

printf("After exchanging, a = %d, b = %d\n", a, b);

return 0;
}

Task 7: Area of Circle


Calculate the area of a circle with a symbolic constant for π.
#include <stdio.h>
#define PI 3.141592

int main() {
int radius;
double area;

printf("Enter the radius value: ");


scanf("%d", &radius);

area = PI * radius * radius;

printf("Area of circle: %.2lf\n", area);

return 0;
}

Task 8: Total and Average of Scores


Calculate total and average scores for three subjects.
#include <stdio.h>

int main() {
int math, chemistry, physics, total;
double average;

printf("Enter the score of mathematics: ");


scanf("%d", &math);

printf("Enter the score of chemistry: ");


scanf("%d", &chemistry);

printf("Enter the score of physics: ");


scanf("%d", &physics);

total = math + chemistry + physics;


average = total / 3.0;

printf("Total score: %d, Average: %.2lf\n", total, average);

return 0;
}

Task 9: Output Character for ASCII Code


Display the character corresponding to an input ASCII code.
#include <stdio.h>

int main() {
int asciiValue;

printf("Enter an ASCII code value in decimal format: ");


scanf("%d", &asciiValue);

printf("The ASCII code entered is the letter '%c'.\n", asciiValue);

return 0;
}

You might also like