-->

if-else programs collection

1) Write a program to know a number is even or odd.

                                                solution
2) Write a program to know a number is divisible by both 3 and 5 or not.

                                                 solution
3) Write program to know a number is positive or negative or zero.
                                                 solution

4)Write a program to know two numbers entered by you are same or not.

                                              solution
5) Write a program to get greatest number among three numbers.

                                                                                                   solution
6)Write a program to know a number entered by you lies between two values/range or not.

                                                                                                  solution
7)Write a program to get smallest number among three numbers.

                                                                                                 solution
8)Write a program to get sum or product or difference or quotient of two numbers using switch.


                                                                                             solution
9) Write a program to know a triangle is right angled or not.

                                                                                         solution

10) Write a program to know a triangle is equilateral or not.

                                                                                         solution
                                                                               
                                                                             
                                                              goto next section




program to know ascii value

// program to know ascii value
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
a=getchar();
printf("its ascii value=%d",a);
getch();
}

program to convert total seconds into hour,minutes and seconds

// program to convert total seconds into hour,minutes and seconds
#include<stdio.h> #include<conio.h> void main() { clrscr(); int total_seconds,hr,minutes,seconds; printf("enter total seconds \n"); scanf("%d",&total_seconds); hr=total_seconds/3600; // to get hour after dividing total seconds by 3600 printf("hours =%d\n",hr); hr=total_seconds%3600; // after getting hours, we have to get total left second minutes=hr/60; // to get total minutes printf("total minutes=%d\n",minutes); seconds=hr%60; // it gives total left seconds as seconds after getting months printf("the seconds=%d\n",seconds); getch(); }

note:
Here I have used same variable again and again. But I you want then you can use different variable

program to convert days into year ,month and days

// program to convert total days into year,month and days #include<stdio.h> #include<conio.h> void main() { clrscr(); int total_days,year,month,days; printf("enter total days \n"); scanf("%d",&total_days); year=total_days/365; // to get year after dividing total days by 365 printf("year =%d\n",year); year=total_days%365; // after getting years, we have to get total left days month=year/30; // to get total months printf("total months=%d\n",month); days=year%30; // it gives total left days as days after getting months printf("the days=%d\n",days); getch(); }

note:
Here I have used same variable again and again. But I you want then you can use different variable.

program to get values in of x in quadratic equation

//program to get values of x in quadratic equation
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2;
printf("enter values of a,b and c\n");
scanf("%f%f%f",&a,&b,&c);
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
printf("the first value=%f\n",x1);
printf("second value is=%f",x2);
getch();
}

note:

according to formula the condition should be satisfied.like
1) (b2-4ac)>0 i.e. b2>4ac
2)a>0 for 2a
otherwise the program terminates abnormally without any result.
later we will see this program with 'if' structure'.

Logically that is said to be right.

program to get total and percentage of a student

// program to get total and percentage of a student
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int english,maths,physics,chemistry;
float total,percentage;
printf(“enter marks of different subjects \n”);
scanf(“%d%d%d%d”,&english,&maths,&physics,&chemistry);
total=english+maths+physics+chemistry;
percentage=(float)total/4; //called type casting to convert total/4 into floating value
printf(“the total marks is=%f\ and percentage=%f\n”,total,percentage);
getch();
}

note:
you can also use like,
percentage=(float)(total/4);
 or
percentage=float(total/4);
you get same output.