HTML Tutorial || Networking Assignment || Computer Full Forms || Ms-Office Shortcut Keys || Ms-Office Notes || Number System Notes || Internet Assignment
JavaScript Tutorial || CSS Tutorial || Operating System Notes || History of Computer Assignment || Netwoking Notes || Computer Fundamentals Notes

C Program to Enter Basic Salary and Calculate Gross Salary of an Employee Using If Else ?


Q:- Write a  C Program to Enter Basic Salary and Calculate Gross Salary of an
       Employee Using If Else ?
      Input
        #include<stdio.h>
        #include<conio.h>
        int main()
   {
float basic,gross,da,hra;
printf(“Enter Basic Salary of an Employee =”);
scanf(“%f”,&basic);
if(basic <=10000)
{
da = basic * 0.8;
hra = basic * 0.2;
}
else if(basic <=20000)
{
da = basic * 0.9;
hra = basic * 0.25;
}
else
{
da = basic * 0.95;
hra = basic * 0.3;
}
gross = basic + hra + da;
printf(“Gross Salary of an Employee =%.2f\n”,gross);
getch();
    }


Output

Enter Basic Salary of an Employee = 22000
Gross Salary of an Employee = 49500.00

C Program to Input Marks of Five Subjects and Find Percentage and Grade Using If Else ?


Q:- Write a C Program to Input Marks of Five Subjects and Find Percentage and
       Grade Using If Else ?
Percentage >=90% : Grade A
Percentage >=80% : Grade B
Percentage >=70% : Grade C
Percentage >=60% : Grade D
Percentage >=40% : Grade E
Percentage <40%  : Grade F
       Input
         #include<stdio.h>
         #include<conio.h>
         int main()
   {
int phy,che,math,eng,comp;
float per;
printf(“Enter Five Subjects Marks =”);
scanf(“%d%d%d%d%d”,&phy,&che,&math,&eng,&comp);
per = (phy+che+math+eng+comp)/5.0;
printf(“Percentage = %.2f\n”,per);
if(per >= 90)
{
printf(“Grade A.”);
}
else if(per >= 80)
{
printf(“Grade B.”);
}
else if(per >= 70)
{
printf(“Grade C.”);
}
else if(per >= 60)
{
printf(“Grade D.”);
}
else if(per >= 40)
{
printf(“Grade E.”);
}
else if(per < 40)
{
printf(“Grade F.”);
}
else
{
printf(“Invalid Input!!!!!!!!!!”);
}
getch();
   }


Output

Enter Five Subjects Marks =
95
95
97
98
90
Percentage = 95.00
Grade A.

C program to Calculate Profit or Loss Using If Else ?


Q:- Write a C program to Calculate Profit or Loss Using If Else ?
      Input
        #include<stdio.h
        #include<conio.h>
        int main()
   {
float cp, sp, amt;
clrscr();
printf(“Enter Cost Price =”);
scanf(”%d”,&cp);
printf(“Enter Selling Price =”);
scanf(“%d”,&cp);
if(cp>sp)
{
amt=cp-sp;
printf(“Loss=%d”,amt);
}
else if(sp>cp)
{
amt=sp-cp;
printf(“Profit=%d”,amt);
}
else
{
printf(“No Profit No Loss.”);
}
getch();
    }


Output

Enter Cost Price = 1000
Enter Selling Price = 1500
Profit = 500

C program to Check Whether the Triangle is Equilateral, Isosceles and Scalene Triangle Using If Else ?


Q:- Write a C program to Check Whether the Triangle is Equilateral, Isosceles and
        Scalene Triangle Using If Else ?
       Input
         #include<stdio.h>
         #include<conio.h>
         int main()
   {
int s1,s2,s3;
clrscr();
printf(“Enter Three Sides of Triangle =”);
scanf(“%d%d%d”,&s1,&s2,&s3);
if(s1==s2 && s2==s3)
{
printf(“Equilateral Triangle.”);
}
else if(s1==s2 || s1==s3)
{
printf(“Isosceles Triangle.”);
}
else
{
printf(“Scalene Triangle.”);
}
getch();
   }


Output

Enter Three Sides of Triangle =
30
20
30
Isosceles Triangle.

C Program to Input all Sides of a Triangle and Check Whether Triangle is Valid or Not Using If Else ?


Q:- Write a C Program to Input all Sides of a Triangle and Check Whether Triangle is
       Valid or Not Using If Else ?
       Input
         #include<stdio.h>
         #include<conio.h>
         int main()
   {
int s1,s2,s3;
clrscr();
printf(“Enter Three Sides of Triangle =”);
scanf(“%d%d%d”,&s1,&s2,&s3);
if((s1+s2)>s3)
{
printf(“Triangle is Valid.”);
}
else if((s2+s3)>s1)
{
printf(“Triangle is Valid.”);
}
else if((s1+s3)>s2)
{
printf(“Triangle is Valid.”);
}
else
{
printf(“Triangle is not Valid.”);
}
getch();
   }


Output

Enter Three Sides of Triangle =
7
4
10
Triangle is Valid.

C Program to Check Whether a Triangle is Valid or Not If Angles are Given ?


Q:- Write a C Program to Check Whether a Triangle is Valid or Not If Angles are Given ?
      Input
        #include<stdio.h>
        #include<conio.h>
        int main()
   {
int a1,a2,a3,sum;
clrscr();
printf(“Enter Three Angles of Triangle =”);
scanf(“%d%d%d”,&a1,&a2,&a3);
sum = a1+a2+a3;
if(sum == 180 && a1 !=0 && a2!=0 && a3!=0)
{
printf(“Triangle is Valid.”);
}
else
{
printf(“Triangle is not Valid.”);
}
getch();
     }


Output

Enter Three Angles of Triangle =
30
60
90
Triangle is Valid.

C Program to Check Whether a Character is Lowercase or Uppercase Alphabet Using If Else ?


Q:- Write a C Program to Check Whether a Character is Lowercase or Uppercase
       Alphabet Using If Else ?
      Input
        #include<stdio.h>
        #include<conio.h>
        int main()
  {
char ch;
clrscr();
printf(“Enter a Character =”);
scanf(“%c”,&ch);
if(ch >=’A’ && ch<=’Z’)
{
printf(“%c is Uppercase Alphabet.”,ch);
}
else
{
printf(“%c is Lowercase Alphabet.”,ch);
}
getch();
}


Output

Enter a Character = D
D is Uppercase Alphabet.

C program to Input a Month Number and Print Number of Days in that Month ?


Q:- Write a C program to Input a Month Number and Print Number of Days in that
        Month ?
        input
          #include<stdio.h>
          #include<conio.h>
          int main()
{
int month;
clrscr();
printf(“Enter Month Number(1-12) = “);
scanf(“%d”,&month);
if(month == 1)
{
printf(“);
{
printf(“31 Days.”);
}
else if(month == 2)
{
printf(“28/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!!!!!!”);
}
getch();
}


Output

Enter a Month Number (1-12) = 12
31 Days.

C Program to Input Week Number and Print Week Day ?


Q:- Write a C Program to Input Week Number and Print Week Day ?
      Input
       #include<stdio.h>
       #include<conio.h>
       int main()
   {
int week;
clrscr();
printf(“Enter a Week Number (1-7) =”);
scanf(“%d”,&week);
if(week == 1)
{
printf(“Monday.”);
}
else if(week == 2)
{
printf(“Tuesday.”);
}
else if(week == 3)
{
printf(“Wednesday.”);
}
else if(week == 4)
{
printf(“Thursday.”);
}
else if(week == 5)
{
printf(“Friday.”);
}
else if(week == 6)
{
printf(“Saturday.”);
}
else if(week == 7)
{
printf(“Sunday.”);
}
else
{
printf(“Invalid Input!!!!!!!!”);
}
getch();
   }


Output

Enter a Week Number (1-7) = 4
Thursday.

C Program to Check Whether a Character is Alphabet, Digit or Special Character ?


Q:- Write a C Program to Check Whether a Character is Alphabet, Digit or
       Special Character ?
      Input
        #include<stdio.h>
        #include<conio.h>
        int main()
   {
char ch;
clrscr();
printf(“Enter a 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);
}
getch();
     }


Output

Enter a Character = f
f is Alphabet.

C program to Input any Alphabet and Check Whether it is Vowel or Consonant ?


Q:- Write a C program to Input any Alphabet and Check Whether it is Vowel or
       Consonant ?
      Input
        #include<stdio.h>
        #include<conio.h>
        int main()
   {
char ch;
clrscr();
printf(“Enter a Character =”);
scanf(“%c”,&ch);
if(ch==’a’||ch==’e’||ch==’i’||ch==’o’||ch==’u’||ch==’A’||ch==’E’||ch==’I’
||ch==’O’||ch==’U’)
{
printf(“%c  is Vowel.”,ch);
}
else
{
printf(“%c is Consonant.”,ch);
}
getch();
        }


Output

Enter a Character = D
D is Consonant.


C Program to Check Whether a Character is Alphabet or Not Using If Else ?


Q:- Write a C Program to Check whether a Character is Alphabet or Not Using If Else ?
      Input
       #include<stdio.h>
       #include<conio.h>
       int main()
   {
char ch;
clrscr();
printf(“Enter a Character =”);
scanf(“%c”,&ch);
if(ch>=’a’ && ch<=’z’ || ch>=’A’ && ch<=’Z’)
{
printf(“%c is Alphabet.”,ch);
}
else
{
printf(“%c is not Alphabet.”,ch);
}
getch();
     }


Output

Enter a Character = S
S is Alphabet.

C Program to Check Whether a Year is Leap Year or Not Using If Else ?


Q:- Write a C Program to Check Whether a Year is Leap Year or Not Using If Else ?
     Input
      #include<stdio.h>
      #include<conio.h>
      int main()
   {
int year;
clrscr();
printf(“Enter a Year =”);
scanf(“%d”,&year);
if(year % 4==0)
{
printf(“%d is Leap Year.”,year);
}
else
{
printf(“%d is not Leap Year.”,year);
}
getch();
     }


Output

Enter a Year = 2016
2016 is Leap Year.

C Program to Check Whether a Number is Even or Odd Using If Else ?


Q:- Write a C Program to Check Whether a Number is Even or Odd Using If Else ?
  Input
       #include<stdio.h>
       #include<conio.h>
       int main()
   {
int num;
clrscr();
printf(“Enter a Number =”);
scanf(“%d”,&num);
if(num%2==0)
{
printf(“%d is Even Number.”,num);
}
else
{
printf(“%d is Odd Number.”,num);
}
getch();
   }


Output

Enter a Number = 2
2 is Even Number.