Академический Документы
Профессиональный Документы
Культура Документы
CODE:
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if(number % 2 == 0)
printf("%d is even.", number);
else
printf("%d is odd.", number);
return 0;
}
CODE:
#include <stdio.h>
int main()
{
int n1, n2, n3;
printf("Enter three numbers: ");
scanf("%d %d %d", &n1, &n2, &n3);
if( n1>=n2 && n1>=n3)
printf("%d is the largest number.", n1);
else if (n2>=n1 && n2>=n3)
printf("%d is the largest number.", n2);
else
printf("%d is the largest number.", n3);
return 0;
}
CODE:
#include <stdio.h>
int main()
{
int age;
printf("Enter the age: ");
scanf("%d", &age);
if(age>=18)
printf("The person is eligible for voting.");
else
printf("The person is not eligible for voting.");
return 0;
}
CODE:
#include <stdio.h>
int main() {
float percentage;
int total_marks=300,scored,sub1,sub2,sub3;
printf("Enter the number in 1st subject: \n");
scanf("%d", &sub1);
printf("Enter the number in 2nd subject: \n");
scanf("%d", &sub2);
printf("Enter the number in 3rd subject: \n");
scanf("%d", &sub3);
scored=sub1+sub2+sub3;
percentage = (float)scored / total_marks * 100.0;
printf("Percentage = %.2f%%\n", percentage);
if(percentage>=60)
printf("1st Division");
else if(percentage>=50)
printf("2nd Division");
else if(percentage>=40)
printf("3rd Division");
else
printf("Fail");
return 0;
}
CODE:
#include<stdio.h>
int main()
{
int a, b, max;
printf("Enter any two number: ");
scanf("%d %d", &a, &b);
if(a>b)
max=a;
else
max=b;
printf("\nMaximum of the two number is: %d", max);
return 0;
}
CODE:
#include<stdio.h>
int main()
{
int num;
printf("Enter a number:\n");
scanf("%d",&num);
if(num>0)
printf("Positive");
else if(num<0)
printf("Negative");
else
printf("Zero");
return 0;
}
CODE:
#include<stdio.h>
int main()
{
int num;
printf("Enter a number:\n");
scanf("%d",&num);
if(num%5==0&&num%11==0)
printf("\nNumber is divisible by both 5 and 11");
else
printf("\nNumber is not divisible by both 5 and 11");
return 0;
}
CODE:
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
CODE:
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
printf("%c is an alphabet.",c);
else
printf("%c is not an alphabet.",c);
return 0;
}
CODE:
#include <stdio.h>
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
printf("Enter an alphabet: ");
scanf("%c",&c);
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
CODE:
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
CODE:
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch >= 'A' && ch <= 'Z')
{
printf("'%c' is uppercase alphabet.", ch);
}
else if(ch >= 'a' && ch <= 'z')
{
printf("'%c' is lowercase alphabet.", ch);
}
else
{
printf("'%c' is not an alphabet.", ch);
}
return 0;
}
14. Problem: Write a program to input month number and print number of days in
the month.
CODE:
#include <stdio.h>
int main()
{
int month;
printf("Enter month number (1-12): ");
scanf("%d", &month);
if(month == 1)
{
printf("31 days");
}
else if(month == 2)
{
printf("28 or 29 days");
}
else if(month == 3)
{
printf("31 days");
}
else if(month == 4)
{
printf("30 days");
}
else if(month == 5)
{
printf("31 days");
}
else if(month == 6)
{
printf("30 days");
}
else if(month == 7)
{
printf("31 days");
}
else if(month == 8)
{
printf("31 days");
}
else if(month == 9)
{
printf("30 days");
}
else if(month == 10)
{
printf("31 days");
}
else if(month == 11)
{
printf("30 days");
}
else if(month == 12)
{
printf("31 days");
}
else
{
printf("Invalid input! Please enter month number between (1-12).");
}
return 0;
}
CODE:
#include <stdio.h>
int main()
{
int angle1, angle2, angle3, sum;
printf("Enter three angles of triangle: \n");
scanf("%d %d %d", &angle1, &angle2, &angle3);
sum = angle1 + angle2 + angle3;
if(sum == 180 && angle1 != 0 && angle2 != 0 && angle3 != 0)
{
printf("Triangle is valid.");
}
else
{
printf("Triangle is not valid.");
}
return 0;
}
CODE:
#include <stdio.h>
int main()
{
int side1, side2, side3;
printf("Enter three sides of triangle: ");
scanf("%d%d%d", &side1, &side2, &side3);
if(side1==side2 && side2==side3)
{
printf("Equilateral triangle.");
}
else if(side1==side2 || side1==side3 || side2==side3)
{
printf("Isosceles triangle.");
}
else
{
printf("Scalene triangle.");
}
return 0;
}
CODE:
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, c, d;
double root1, root2;
printf("Enter a, b and c where a*x*x + b*x + c = 0\n");
scanf("%d %d %d", &a, &b, &c);
d = b*b - 4*a*c;
if (d < 0) {
printf("First root = %.2lf + j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
printf("Second root = %.2lf - j%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
}
else {
root1 = (-b + sqrt(d))/(2*a);
root2 = (-b - sqrt(d))/(2*a);
printf("First root = %.2lf\n", root1);
printf("Second root = %.2lf\n", root2);
}
return 0;
}
CODE:
#include <stdio.h>
int main()
{
int cp,sp, amt;
printf("Enter cost price: ");
scanf("%d", &cp);
printf("Enter selling price: ");
scanf("%d", &sp);
if(sp > cp)
{
amt = sp - cp;
printf("Profit = %d", amt);
}
else if(cp > sp)
{
amt = cp - sp;
printf("Loss = %d", amt);
}
else
{
printf("No Profit No Loss.");
}
return 0;
}
_________________________________