## C Program to Find Simple Interest in C Programming.

Program to find Simple Interest

#include<stdio.h>

#include<conio.h>

void main()

{

float p,r,t,si;

printf("Enter the value of Principle=");

scanf("%f",&p);

printf("Enter the value of Rate=");

scanf("%f",&r);

printf("Enter the value of Time (Year) =");

scanf("%f",&t);

si=p*r*t/100;

printf("Answer is=%f",si);

getch();

}

Output:-

Continue Reading →

## C Program to Find the greatest number between 3 Numbers.

C Program to Find Greatest Number Between 3 Numbers.

#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
printf("Enter the three Number=");
scanf("%d%d%d",&a,&b,&c);
if (a>b)
{
if (a>c)
{
printf("A is greater number");
}
else
{
printf("C is greater number");
}
}
else

if(b>c)
{
printf("B is greater number");
}
else if (a==b && a==c)
{
printf("Numbers are equal");
}
else
{
printf("C is greater number");
}
getch();
}

Output :-

Continue Reading →

## C Program to find Odd & Even Number given by the User.

C Program to Find ODD & EVEN Number given by the user.

#include<stdio.h>

void main()

{

int a;

printf("Enter the Number");

scanf("%d",&a);

if (a%2==0)

printf("Number is Even");

else

printf("Number is Odd");

getch();

}

Output :-

Continue Reading →

## Nested IF-Else in C Programming

Hey Friend, in our last tutorial we have seen about if statements, and if-else statements. In the if statement only one condition is check and if the condition is true then the output will be shown on the display. And on the other hand, we have also seen that if you have two conditions then if-else were used to check those conditions.

Now, during the high-level programming, you have to check more than two conditions. For Example, you have to write a program to check whether

• Num1 is less than num2
• Num1 is greater than num2
• Num1 is equal to num2

In that case, you have to use a nested if-else statement on your programs.

Nested IF – ELSE

A nested if-else statement is used when a series of decisions were used to check through your program. As the name suggests, Nesting means using an if-else construct within another one. But guys basically there is no limitation to nesting. But the programmers nest up to 3 blocks only. You could use more if you want.

Syntax of the nested if-else statement

if (condition)

{

Statement 1

Statement 2 and so on

}

else

{

if (condition)

{

Statement a

Statement b

}

else

{

Statement c

Statement d

}

}

I know it is a bit complex for beginners but I will explain it to you in the easiest way. So let’s try to understand this.

Look at the syntax. you see that I am nested the if-else statement into the else statement of the syntax. Now when the code is executed then the compiler first checks the if condition (primary if block) if the condition is false of if statement then the compiler goes on the else part. Now in the else block it will check the if condition (secondary if block). If the condition is not true of secondary if block, then the compiler is print the else (secondary else part) as output.

You can also nested if-else on the if(primary statement). If you haven’t understood it yet, then don’t worry let try it with a simple program.

Program to find out the greater number between two numbers.

#include<stdio.h>

int main()

{

int a, b;

printf("Enter Number A & B = ");

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

if(a>b)

{

printf("A is Greater than B");

}

else{

if(b>a)

{

printf("B is Greater than A");

}

else{

printf("Numbers are Equal");

}

}

getch();

}

Output :-

Explanation :-

First, we declare two integer variable name a and b. After the declaration of the variable name. We take input from the user in variable a and variable b.

Now, we use nested if-else to check the greater number between a and b. So there are three possibilities that occur among checking the numbers. It should be:-

• A is greater than B
• B is greater than A
• Both Number are Equal

So, in the first if block of the part,  we check the condition. The condition is whether integer a is Greater than integer B if true then print the Message to the user that “A is greater than B”. if the first condition is true then the program is print the output.  Or if the condition is not true then the program will go on else block.

Now, here are the two different conditions the first one is to check whether the integer B is Greater than A. If true then print the message to the user that “B is greater than B”. if this condition is not true then the else part is automatically executed by default.

Hope you all understood this. If you have any query then comment it down. For more keep visit here.

Continue Reading →

## If-Else Condition in C Programming Part - II

Hey Friend, till now we have studied about only if statement. If you do not know about IF statement please read the previous tutorial before reading this. In if statement whenever the condition is true a set of instructions will proceed running. But every coin has two faces, till now we only learned about one condition. If the condition is true then the code will execute. In high-level programming, you have to code both situations such as if the first condition is true then a set of instructions will execute & if the condition is not true then the second set of instructions execute. This work is done using if-else statements.

Syntax of IF-Else Condition

If (condition)

{

Statement 1;

Statement 2;

So on…;

}

Else{

{

Statement 1;

Statement 2 and so on…;

}

Note that:-

1. The Statement inside if and else keyword and generally known as if block and else block respectively.

2. The parenthesis inside the if-else block can be dropped if there is only one condition exists.

3. You should not use any condition in the else keyword. The statements under else will be executed only if the condition with if statement is false. So it is treated as the default choice.

4.  Notice that the else part or statement of the program is placed just below the if part. And the statement of those blocks has indented to the right. This is a formatting convention that means just to write a program easier or understandable way. Look at the below program to understand in a better way.

Program to find that the given number is a positive number or a negative number.

#include <stdio.h>

void main()

{

int number;

printf("Enter a number to check if it is negative or positive :");

scanf("%d",&number);

if(number<0)

{

printf("Number is negative");

}

else

{

printf("Number is positive");

}

}

Output :-

Explanation of the Program

I have already told the meaning of these (include, printf, int main) functions earlier. If you don’t know please check the previous post. In this program, we declare a variable name (number) as an integer value given by the user.

Now we are going to check the number whether it is a positive number or a negative number.  So in the if block we check, is this number is smaller than zero? If yes then the program of (if block) executes and gives us the output.

Or if the number is greater than zero then the else block starts to execute and give us the output.

Hope you all understand the program and if you have any query then comment below I will definitely try to explain with another example.

Continue Reading →

## C Program to Find ASCII Value of Character.

C program to find out the ASCII code of any Character.

Method 1

#include<stdio.h>

void main()

{

int a;

char ch;

printf("Enter any character:");

scanf("%c",&ch);

a=ch;

printf("ASCII value of %c is %d",ch,a);

getch();

}

Method 2

#include <stdio.h>

void main()

{

char c;

printf("Enter any character =");

scanf("%c", &c);

printf("ASCII Value is = %d",c);

return 0;

}

Output:-

Continue Reading →

## C Program to find the average marks of 5 subjects -- C Programming

Program To Find Average of 5 Subjects

#include<stdio.h>

int main()

{

int a, b, c, d, e, sum;

float ave;

printf("Enter Marks of Subjects 1 =");

scanf("%d",&a);

printf("Enter Marks of Subjects 2 =");

scanf("%d",&b);

printf("Enter Marks of Subjects 3 =");

scanf("%d",&c);

printf("Enter Marks of Subjects 4 =");

scanf("%d",&d);

printf("Enter Marks of Subjects 5 =");

scanf("%d",&e);

sum = a+b+c+d+e;

ave = sum/5;

printf("\nSum of the Marks are :- %d ", sum);

printf("Average of the Marks are :- %f", ave);

getch();

}

Output :-

Continue Reading →

## IF-Else Condition in C Programming Part - 1

If Else Condition in C Programming

Hey Friends, in day-to-day life people take a lot of decisions by themselves. For ex:-

1. If it rains today, then I will not go to college

If not then I will go

2. If the train is late, I will catch the train

If not, I will not be able to get the train

Taking decisions in programming is an important part of it. C language also uses decision instruction. In C Programming there are mainly 3 types of decision control instruction

1. If

2. If-else

3. Switch

Till now we have studied sequence control instruction. In that instruction, Statements are executed in the order in which they have written or appear. But During the high-level projects, we need to execute a set of instructions by conditions. If the first condition is true then code will run or if the condition is not true (false) then the other condition runs or execute.

So the selection of the condition (true or false) of instructions is called Decision.

Now, In this article, we gonna learn about decision control instruction.

If Statement in C programming

In C programming, (if) is a keyword to execute an instruction if the instruction is true.  In Simple World, if the given condition is true your code will be run. If not then the code didn’t run.

The Syntax of the if the condition was given below:-

If (condition)

{

Statement 1;

Statement 2;

Statement 3;

}

Let us Check through an example :-

#include <stdio.h>

int main()

{

int a;

printf("Enter the Number = ");

scanf("%d", &a);

if (a<=10)

{

printf("A is Smaller than 10");

}

return 0;

}

Output:-

Look at the function of the code:-

In this program, we take a numeric input from the user to check whether a number is greater than 10 or smaller than 10.

If the numerical number is smaller than 10. Then the output will display a message to the user that your input is smaller than 10.

But if the number is greater than 10. Nothing will be shown on the display. Because we give only one statement in this program.

So that’s all for today guys.. we will continue the rest of the function in the next part of the article. if you have any query related to this comment below.

Continue Reading →

## C Program to Add Two Integer Number -- C Programs

In our previous tutorial, we had made a simple program of C language in which we had printed Hello World on the display. Hope you guyz understood that program. Now, today I am going to make another C program which takes the 2 input from the user in the numerical value and gives us the sum of these two numerical value.  So Let’s Begin…

C Program to Add Two Numerical Value.

#include<stdio.h>

int main()

{

int A,B,C;

printf("Enter the value of A=");

scanf("%d",&a);

printf("Enter the value of B=");

scanf("%d",&b);

c=a+b;

printf("Answer is=%d",c);

getch();

}

Output :-

Look at the function used in the above code

1. In the first line of code we include a header file named <stdio.h> which is used to add the printf, scanf function in the program.

2. On the second line of the code we use int main () function. It shows that your program starts executing from here.

3. After that we declare 3 variable (A, B, C) respectively. The first variable A store the first numerical value and the second variable B store the second numerical value and the sum of these two number are stored on the third variable C.

4. After the declaration of the variable we give the message to the user to enter the first number. We use printf() function to give the message which is printed on the monitor screen.

5. After the message the value provided by the user was stored in the first variable name A. we assign the value into A variable by using scanf() function.

6. In scanf() function we use %d on it. %d indicates the compiler that the user gives an integer value to it.

7. You also notice that we use & (and) symbol on both scanf function what are their mean. The & symbol tell the compiler that the input given by the user is stored on the specific location. (The first value stored on A variable and the second value stored on B variable respectively).

8. At the last line of code we use a function name getch(). This function is used to hold the output screen until the user presses any button or click on the output screen.

Continue Reading →

## Contact Form

Name

Email *

Message *

Mad About Computer. Powered by Blogger.