0% found this document useful (0 votes)
22 views14 pages

C Assignment All

Uploaded by

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

C Assignment All

Uploaded by

yogesh bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 14

1. #include <stdio.

h>

int main()
{
int a;
printf("enter the value of a ");
scanf("%d",&a);
if(a>10){
printf("number is greater than 10");
}
return 0;
}

2. #include <stdio.h>

int main()
{
int a;
printf("enter the value of a ");
scanf("%d",&a);
if(a>10){
printf("number is greater than 50");
}
return 0;
}

3. #include <stdio.h>

int main()
{
int a;
printf("enter the value of a ");
scanf("%d",&a);
if(a>10){
printf("number is greater than 87");
}
return 0;
}

4. int main()
{
int a;
printf("enter the value of a ");
scanf("%d",&a);
if(a==1){
printf("one");
}
else{
printf("your input is not valid ");
}
return 0;
}

6.#include <stdio.h>

int main()
{
char a;
printf("enter the character");
scanf("%c",&a);
if(a=='a'){
printf("apple");
}
else{
printf("your input is not valid ");
}
return 0;
}

7.#include <stdio.h>

int main()
{
char a;
printf("enter the character");
scanf("%c",&a);
if(d=='d'){
printf("drum");
}
else{
printf("your input is not valid ");
}
return 0;
}

8.#include <stdio.h>

int main()
{
int num;
printf("enter the value of num");
scanf("%d",&num);
if(num%2==0){
printf("even");
}
else{
printf("odd");
}
return 0;
}

9. #include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 5 == 0) {
printf("%d is divisible by 5.\n", num);
} else {
printf("%d is not divisible by 5.\n", num);
}
return 0;
}

10. #include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 10 == 0) {
printf("%d is divisible by 10.\n", num);
} else {
printf("%d is not divisible by 10.\n", num);
}

return 0;
}

11. #include <stdio.h>

int main() {
int num1, num2, sum;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("The sum of %d and %d is %d.\n", num1, num2, sum);

return 0;
}

12. #include <stdio.h>

int main() {
int num1, num2, sub;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
sub = num1- num2;
printf("The sub of %d and %d is %d.\n", num1, num2, sub);

return 0;
}

13.

#include <stdio.h>

int main() {
int num1, num2, sub;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
sub = num1- num2;
printf("The sub of %d and %d is %d.\n", num1, num2, sub);
return 0;
}

14. #include <stdio.h>

int main() {
int num1, num2, product;

printf("Enter the first number: ");


scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);

product = num1 * num2;

printf("Result of multiplication: %d\n", product);

return 0;
}

15. #include <stdio.h>

int main() {
int num1, num2, remainder;

printf("Enter the first number: ");


scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);

remainder = num1 % num2;


printf("Result of modulo operation: %d\n", remainder);

return 0;
}

16. #include <stdio.h>

int main() {
int num1, num2, ;

printf("Enter the first number: ");


scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);

remainder = num1 % num2;


printf("Result of modulo operation: %d\n", remainder);

return 0;
}

17. #include<stdio.h>
int main()
{
int num1,num2,div;
printf("Enter First Number : ");
scanf("%d", &num1);
printf("\nEnter Second Number : ");
scanf("%d",&num2);
div=num1/num2;
printf("\nDivision of %d & %d is = %d",num1,num2,div);
return 0;
}
#include <stdio.h>

int main() {
int age;

printf("Enter your age: ");


scanf("%d", &age);
if (age >= 18) {
printf("You are eligible to vote!\n");
} else {
printf("You are not eligible to vote yet.\n");
}

return 0;
}

18. #include <stdio.h>


#include <ctype.h>

int main() {
char character;

printf("Enter a character: ");


scanf(" %c", &character);

if (character == 'Q' || character == 'W' || character == 'E' ||


character == 'R' || character == 'T' || character == 'Y' ||
character == 'U' || character == 'I' || character == 'O' ||
character == 'P') {
printf("The character '%c' belongs to the upper line of the QWERTY
keyboard.\n", character);
} else {
printf("The character '%c' does not belong to the upper line of the QWERTY
keyboard.\n", character);
}

return 0;
}

19.#include <stdio.h>
#include <ctype.h>

int main() {
char character;

// Prompt the user to input a character


printf("Enter a character: ");
scanf(" %c", &character);

// Check if the character belongs to the middle line


if (character == 'a' || character == 's' || character == 'd' ||
character == 'f' || character == 'g' || character == 'h' ||
character == 'j' || character == 'k' || character == 'l') {
printf("The character '%c' belongs to the middle line of the QWERTY
keyboard.\n", character);
} else {
printf("The character '%c' does not belong to the middle line of the QWERTY
keyboard.\n", character);
}

return 0;
}

***********************************************************************************
*****************************************************************

1. #include <stdio.h>

int main()
{
int a = 34;
int b = 4;
int c = 8;
int result = a+(b*b)-c;
printf("%i",result);
return 0;
}

2. #include <stdio.h>

int main()
{
float a = 3.1;
float b = 6.7;
float c = 2.2;
float d = 5.4;
float result = a*b-(c*c)-d;
printf("%f",result);
return 0;
}

3. #include <stdio.h>

int main()
{
float a = 2.3;
int b = 7;
float c = 3.4;
int d = 6;
float e = 2.3;
int f = 2;
float result = a-b+(c*d)-e/f;
printf("%f",result);
return 0;
}

4. #include <stdio.h>

int main()
{
int a = 23;
int b = 2;
int c = 9;
int d = 34;
int result = a*b-c+d;
printf("%i",result);
return 0;
}
***********************************************************************************
**************************************************

1. #include <stdio.h>

int main() {
int day;

printf("Enter a number representing a day of the week (1-7): ");


scanf("%d", &day);

if (day == 1) {
printf("Sunday\n");
} else if (day == 2) {
printf("Monday\n");
} else if (day == 3) {
printf("Tuesday\n");
} else if (day == 4) {
printf("Wednesday\n");
} else if (day == 5) {
printf("Thursday\n");
} else if (day == 6) {
printf("Friday\n");
} else if (day == 7) {
printf("Saturday\n");
} else {
printf("Invalid\n");
}

return 0;
}

2. #include <stdio.h>

int main() {
int month;

printf("Enter a number representing a month (1-12): ");


scanf("%d", &month);

if (month < 1 || month > 12) {


printf("Invalid month\n");
} else {
printf("The month is ");
if (month == 1) {
printf("January");
} else if (month == 2) {
printf("February");
} else if (month == 3) {
printf("March");
} else if (month == 4) {
printf("April");
} else if (month == 5) {
printf("May");
} else if (month == 6) {
printf("June");
} else if (month == 7) {
printf("July");
} else if (month == 8) {
printf("August");
} else if (month == 9) {
printf("September");
} else if (month == 10) {
printf("October");
} else if (month == 11) {
printf("November");
} else if (month == 12) {
printf("December");
}
printf("\n");
}

return 0;
}

3. #include <stdio.h>

int main() {
char ch;

printf("Enter a character: ");


scanf(" %c", &ch);
if (ch == 'Q' || ch == 'W' || ch == 'E' || ch == 'R' || ch == 'T' || ch == 'Y'
|| ch == 'U' || ch == 'I' || ch == 'O' || ch == 'P') {
printf("Upper line\n");
} else if (ch == 'A' || ch == 'S' || ch == 'D' || ch == 'F' || ch == 'G' || ch
== 'H' || ch == 'J' || ch == 'K' || ch == 'L') {
printf("Mid line\n");
} else if (ch == 'Z' || ch == 'X' || ch == 'C' || ch == 'V' || ch == 'B' || ch
== 'N' || ch == 'M') {
printf("Lower line\n");
} else {
printf("Input mismatch\n");
}

return 0;
}

4. #include <stdio.h>

int main()
{
char a;
printf("enter the value ");
scanf("%c",&a);
if(a=='a'){
int n1,n2,n3;
printf
}
else if(a=='m'){
multiplication
}
else{
printf("input mismatch");
}
return 0;
}

5.#include <stdio.h>

int main() {
int number;

printf("Enter a number: ");


scanf("%d", &number);

if (number % 2 == 0) {
printf("This number is divisible by 2\n");
} else if (number % 5 == 0) {
printf("This number is divisible by 5\n");
} else if (number % 7 == 0) {
printf("This number is divisible by 7\n");
} else {
printf("Input mismatch\n");
}

return 0;
}

6. #include <stdio.h>

int main() {
int num1, num2;

printf("Enter the first number: ");


scanf("%d", &num1);

printf("Enter the second number: ");


scanf("%d", &num2);

if (num1 > num2) {


printf("The maximum number is: %d\n", num1);
} else {
printf("The maximum number is: %d\n", num2);
}

return 0;
}

7. #include <stdio.h>

int main() {
int num1, num2, num3;

printf("Enter the first number: ");


scanf("%d", &num1);

printf("Enter the second number: ");


scanf("%d", &num2);

printf("Enter the third number: ");


scanf("%d", &num3);

if (num1 >= num2 && num1 >= num3) {


printf("The maximum number is: %d\n", num1);
} else if (num2 >= num1 && num2 >= num3) {
printf("The maximum number is: %d\n", num2);
} else {
printf("The maximum number is: %d\n", num3);
}

return 0;
}

8. #include <stdio.h>

int main() {
int num1, num2, num3, num4, num5;

printf("Enter the first number: ");


scanf("%d", &num1);

printf("Enter the second number: ");


scanf("%d", &num2);

printf("Enter the third number: ");


scanf("%d", &num3);

printf("Enter the fourth number: ");


scanf("%d", &num4);

printf("Enter the fifth number: ");


scanf("%d", &num5);

int max = num1;

if (num2 > max) {


max = num2;
}

if (num3 > max) {


max = num3;
}

if (num4 > max) {


max = num4;
}

if (num5 > max) {


max = num5;
}

printf("The maximum number is: %d\n", max);


return 0;
}

9. #include <stdio.h>
float fahrenheitToCelsius(float fahrenheit) {
return (fahrenheit - 32) * 5 / 9;
}
float celsiusToFahrenheit(float celsius) {
return (celsius * 9 / 5) + 32;
}

int main() {
char choice;
float temperature;

printf("Enter 'c' to convert from Celsius to Fahrenheit or 'f' to convert from


Fahrenheit to Celsius: ");
scanf(" %c", &choice);

if (choice == 'c' || choice == 'C') {


printf("Enter the temperature in Celsius: ");
scanf("%f", &temperature);
printf("%.2f Celsius is equal to %.2f Fahrenheit\n", temperature,
celsiusToFahrenheit(temperature));
} else if (choice == 'f' || choice == 'F') {
printf("Enter the temperature in Fahrenheit: ");
scanf("%f", &temperature);
printf("%.2f Fahrenheit is equal to %.2f Celsius\n", temperature,
fahrenheitToCelsius(temperature));
} else {
printf("Invalid choice\n");
}

return 0;
}

10. #include <stdio.h>

int main() {
char choice;
float temperature;

printf("Enter 'c' to convert from Celsius to Fahrenheit or 'f' to convert from


Fahrenheit to Celsius: ");
scanf(" %c", &choice);

if (choice == 'c') {
printf("Enter the temperature in Celsius: ");
scanf("%f", &temperature);
printf("Temperature in Fahrenheit: %.2f\n", (temperature * 9 / 5) + 32);
} else if (choice == 'f') {
printf("Enter the temperature in Fahrenheit: ");
scanf("%f", &temperature);
printf("Temperature in Celsius: %.2f\n", (temperature - 32) * 5 / 9);
} else {
printf("Invalid choice\n");
}
return 0;
}

11.
#include <stdio.h>

int main() {
float height_cm, height_m;

printf("Enter the height of the person in centimeters: ");


scanf("%f", &height_cm);

height_m = height_cm / 100;

if (height_m < 1.6) {


printf("The person is categorized as low height.\n");
} else if (height_m >= 1.6 && height_m <= 1.8) {
printf("The person is categorized as mid height.\n");
} else {
printf("The person is categorized as high height.\n");
}

return 0;
}

12.#include <stdio.h>

int main() {
int roll_number;
char student_name[50], fname[50], mname[50], address[100], contact[15];
int physics, chemistry, computer_application;
int total;
float percentage;

printf("Input the Roll Number of the student: ");


scanf("%d", &roll_number);

printf("Input the Student Name: ");


scanf("%s", student_name);
printf("Input the Father's Name: ");
scanf("%s", fname);
printf("Input the Mother's Name: ");
scanf("%s", mname);
printf("Input the Student's Address: ");
scanf("%s", address);
printf("Input the Student's Contact: ");
scanf("%s", contact);

printf("Input the marks of Physics, Chemistry and Computer Application: ");


scanf("%d %d %d", &physics, &chemistry, &computer_application);

total = physics + chemistry + computer_application;

percentage = (float)total / 3;
char division;
if (percentage >= 60) {
division = 'First';
} else if (percentage >= 45) {
division = 'Second';
} else if (percentage >= 33) {
division = 'Third';
} else {
division = 'Fail';
}

printf("Total Marks: %d\n", total);


printf("Percentage: %.2f%%\n", percentage);
printf("Division: %c\n", division);

return 0;
}

13. *******************************************************************************
#include<stdio.h>
int
main ()
{
int a, b, c, d, e;
printf("enter the value of a,b,c,d and e : ");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
if (a >= b && a >= c && a >= d && a >= e)
{
printf ("the maximum number is : %d\a",a);
}
else if (b >= a && b >= c && b >= d && a >= e)
{
printf ("the maximum number is:%d\b",b);
}
else if(c>=a&&c>=b&&c>=d&&c>=e){
printf ("the maximum number is:%d\c ",c);
}
else if (d >= a && d >= b && d >= c && d >= e)
{
printf ("the maximum number is:%d\d",d);
}
else if(e>=a&&e>=b&&e>=c&&e>=d){
printf ("the maximum number is: %d\e",e);
}
return 0;
}

14.#include <stdio.h>

int main() {
float marks, percentage;
printf("Enter marks obtained: ");
scanf("%f", &marks);

// Calculate percentage
percentage = (marks / 100) * 100;

// Display percentage
printf("Percentage: %f\n", percentage);

// Determine grade
if (percentage < 25)
printf("Grade: F\n");
else if (percentage >= 25 && percentage < 45)
printf("Grade: E\n");
else if (percentage >= 45 && percentage < 50)
printf("Grade: D\n");
else if (percentage >= 50 && percentage < 60)
printf("Grade: C\n");
else if (percentage >= 60 && percentage <= 80)
printf("Grade: B\n");
else
printf("Grade: A\n");

return 0;
}

You might also like