Friday, 6 July 2012

Credit Cards - “Filling pockets or making bankrupt”




Credit Cards -

        Many of us might have heard about credit cards and now a days people also consider this as a status symbol. Look I have a gold credit card, I have premium. But when asked many of them are not able to differentiate between those credit cards. Many people even don't the difference between a credit card and a debit card. 


A Credit Card is like a loan you borrow something by agreeing that you would pay for it in the future along with some interest (extra money) whereas a Debit Card means you have something in your bank account and you are using it. 

A Credit Card offers various features such as an Alternative to Cash, Record keeping of all transactions, Gifts and other Coupons,  a credit limit etc. Every customer has different financial needs and based on those financial needs there is a different credit card. Credit cards can be divided into 5 broad categories - Standard cards, Premium cards, Secured cards, Charge cards, Prepaid cards. Credit card offer various benefits such as refund on the loss, stolen of goods purchased through credit cards. 

Conclusion - Credit card is very convenient financial short-term lending facility available to a credit cardholder.


Follow Us on Facebook - Assignment Hub

Wednesday, 4 July 2012

Logic for implementing data encryption and decryption


Suppose there is one message and the user enters a number/key (3 digit number). Now the data need to be encrypted in a form that is unreadable and if the number is entered again then data need to be decrypted again back to the readable form. 

Logic - 

                Extract the first and last digit of the number. For example, the first digit is 3 and last digit is 4 replace the character at 3rd position with 4th and 4th position with the 3rd position. Then multiply the first digit and last digit with 2 and continue the same operation of replacing the characters until any value whether its first or last exceeds the message length. 

Note - This process can be continued as  many times, the more the times the steps are repeated more difficult it will be to get the original message. 

After doing this all the spaces can be replaces with a special character. 

The decryption process is totally reverse. First replace all the special character with the spaces (the special character which was used to replace the space before). Scan the number/key again because until the same number/key will be entered, the message need not to be decrypted. After that extract the first and last digit multiply it with 2 until the value of any digit whether first number and last number is greater than the message length and the previous value of first and last digit before multiplying it with 2 must be stored (previous value means that if corresponding value of first and last digit are (4.2),(8,4),(16,8) so for (16,8) (8,4) must be kept). and now replace the characters at those particular positions (at previous value that was kept where the value exceeded the message length) and then divide the values(first and last digit) by 2 (during encryption we multiplied them with 2) and continue the process until the value of first and last digit is not same as the first and last digit of the number being scanned. You again got the decrypted data.

Note - The message length should be even, if it is not convert it to even first by adding a space at the last position.

 For any query do comment..and we can be reached as Assignment Hub on Facebook.


Swapping of numbers without using a temporary variable in C


Code - 


//_________Swap 2 Numbers without using a temporary variable _________

//________________Include Header Files_____________

#include<stdio.h>

#include<conio.h>

//_Header field included mainly for the getch() function__

int main()

//_______Function from where program execution starts_________________

{
int first_number = 0, second_number = 0;

printf("\n\n\t\t   ______Program will Swap 2 Numbers_______");

printf("\n\n\n Enter the First Number  - ");

//_________Prompting the user to enter First Number_________

scanf("%d",&first_number);

//___Reading the user_input and storing input in variable first_number__

printf("\n Enter the Second Number - ");

//_________Prompting the user to enter Second Number_________

scanf("%d",&second_number);

//_________Reading the user_input and storing input in variable second_number________

//______________Displaying the user input once again________________

printf("\n\n\t Numbers before swapping :- \n\n\t\t First  - %d \n\n\t\t Second - %d", first_number, second_number);

//____________Swapping of two numbers________________

/* logic changes here instead of taking a temporary variable add the numbers and assign the value to the first variable */

first_number = first_number + second_number;

/* from the new number subtract the second number and assign it to second number as

the second number is still the same as entered by the user */

second_number = first_number - second_number;

/* Repear the same step for first number subtract second number from first as now the second number has been changed */

first_number = first_number - second_number;


//__________Displaying the numbers after swapping____________

printf("\n\n\t Numbers after swapping :- \n\n\t\t First  - %d \n\n\t\t Second - %d", first_number, second_number);

printf("\n\n________________________________________________________________________________");

getch();

return 0;

//__return 0 tells the compiler that program has executed succesfully without any error__


}


Tuesday, 3 July 2012

Program to display a pattern in form of reverse stairs in C


Code - 


//_________Program to display a pattern in form of reverse stairs________________

/*_________Sample Pattern_______________________

pattern -
4444
333
22
1

1, 2, 3, 4 represent the coloumn number in a row.....Number of rows will be inputted by the user___*/

//___________________Import Header Files__________________

#include<stdio.h>

#include<conio.h>

int main()

  //__________Main Function from where the program execution starts____________

{
int row = 0, coloumn = 0, user_input;

//____Variable declaration and initialization________


printf("\n\n\t     _________Program will display the pattern_________");

printf("\n\n Enter the total number of coloumns required - ");

//________Prompting the user to enter the total number of rows______

scanf("%d", &user_input);

//____Reading the user input and storing it in variable user_input___

printf("\n\n Pattern - \n\n");

for(coloumn = user_input; coloumn >= 1 ; coloumn--)

       //_____Looping construct from user_input to 1____
{
printf("\t"); //_______Display 5 spaces_____

for(row = 1; row <= coloumn; row++)
{
printf(" %d",coloumn);

//_____Display the coloumn number (total coloumns in a row)________

                }
printf("\n");


//_____Taking the cursor to the next line_______

}


getch();

return 0;
}

Follow Us on Facebook - Assignment Hub

Remove spaces between substrings of string in C


Code - 


/*__Program to remove two consecutive spaces between various substrings of a string___*/

//___________Inlcuding header files___________

#include<stdio.h>

#include<conio.h> //_________Mainly included for the getch function_____________

#include<string.h> //_________Mainly included for gets() function used to scan a string___________

int main()
{
char original_string[20];

int i = 0, j = 0;

printf("\n\n  __ Program to remove consecutive spaces between sub-strings of a string __");

printf("\n\n\n\n\t   Enter the String - ");

gets(original_string);

for(i = 0; original_string[i] != '\0'; i++)
{
if (original_string[i] == 32)
{
if (original_string[i+1] == 32)
{
for (j = i; original_string[j] != '\0'; j++ )
{
original_string[j] = original_string[j+1];
}

i = i - 1;
}
}

}

printf("\n\n\t       Final String - ");

puts(original_string);

getch();
}

Follow Us on Facebook - Assignment Hub

Uppercase to lowercase in C


Code -


//__________Program to know the ASCII value of a character____________

/* To convert a character into lowercase 32 must be added to its ASCII value */

//__________Including header files___________

#include<stdio.h>

#include<conio.h>

//__________Mainly included for the getch() function________

#include<string.h>


//__________Mainly included for the gets() function to read the string_______

int main()
{
char input_string[25], original_string[25];

int counter = 0;

printf("\n\n\t\t__ Program to convert a string into lowercase __");

printf("\n\n\n\tEnter the String - ");

gets(input_string);

strcpy(original_string,input_string);

//______ strcpy(string1, string2) function is used to copy string2 in string1 ______

for(counter = 0 ; input_string[counter]; counter ++)
{
if ((input_string[counter] >= 65) && (input_string[counter] <= 91))
{
input_string[counter] = input_string[counter] + 32;
}
}

printf("\n\n\t\t   Original String         -   ");

puts(original_string);

printf("\n\t\t   String in Lowercase     -   ");

puts(input_string);



getch();

return 0;
}

Display the ASCII value of a character in C



Code -


//__________Program to know the ASCII value of a character____________

//__________Including header files___________

#include<stdio.h>

#include<conio.h> //__________Mainly included for the getch() function________

int main()
{
char input_character;

printf("\n\n\t__ Program to display the ASCII value of a character ___");

printf("\n\n\n  Enter Character - ");

input_character = getche();

printf("\n\n\t\t   __ ASCII value for %c is %d __ ",input_character, input_character);

getch();

return 0;

}

Follow Us on Facebook -  Assignment Hub

Delete an element from an array in C


Code - 


//____Program to delete an element from an array at a particular position____

//______Including Header Files___

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

int main()
{
int elements[9], position = 0, element = 0, counter = 0;

printf("\n\t______ Delete an element from an array at a particular position ______");

printf("\n\n   Emter the elements :- ");

for(counter = 0 ; counter <= 8; counter ++)
{
printf("\n\n\t%d element - ", counter + 1);

scanf("%d", &elements[counter]);
}

system("cls");

printf("\n\t______ Delete an element from an array at a particular position ______");

printf("\n\n  Elements entered in array :-  \n\n");

for(counter = 0; counter <= 8; counter ++)
{
if (counter % 3 == 0)
{
printf("\n\n");
}
printf("  '%d' Position - %d        ", counter + 1, elements[counter]);
}

printf("\n\n\t Enter the position to delete an element :- ");

scanf("%d", & position);

element = elements[position - 1];

for(counter = position - 1; counter <= 7; counter ++)
{


elements[counter] = elements[counter + 1];
}

printf("\n\n  Elements entered in new array :-  \n\n");

for(counter = 0; counter <= 7; counter ++)
{
if (counter % 3 == 0)
{
printf("\n\n");
}
printf("  '%d' Position - %d        ", counter + 1, elements[counter]);
}

printf("\n\n  Element deleted - %d at position %d ", element, position);

getch();


}

Follow Us on Facebook - Assignment Hub

Convert Decimal Number into Binary Number in C ( Version 1 )


Code -


//__Program to convert Decimal number into Binary number Version 1___

/* Best works for number less than 999 */

//___________Including header files_____________

#include<stdio.h>

#include<conio.h>

int main()
{
int decimal_number = 0, remainder = 0, temp_number = 0, binary_number = 0, counter = 1;

printf("\n\n\t__ Program to convert Decimal number into Binary number __ ");

printf("\n\n\n  Enter the Decimal Number - ");

scanf("%d",&decimal_number);

temp_number = decimal_number;

while(temp_number != 0)
{
remainder = temp_number % 2;

temp_number = temp_number / 2;

binary_number = binary_number  + remainder * counter ;

counter = counter * 10;
}

printf("\n\n\t   Binary equivalent of Decimal number - %d is %d",decimal_number, binary_number);

getch();

return 0;
}

Follow Us on Facebook - Assignment Hub

Swapping of numbers in C


Code -


//_________Swap 2 Numbers inputted by the user_________

//________________Include Header Files_____________

#include<stdio.h>

#include<conio.h>

//_______Header field included mainly for the gecth() function________

int main()

//_______Function from where program execution starts_________________

{
int first_number = 0, second_number = 0, temp_number = 0;

printf("\n\n\t\t   ______Program will Swap 2 Numbers_______");

printf("\n\n\n Enter the First Number  - ");

//___Prompting the user to enter First Number_____

scanf("%d",&first_number);

//___Reading the user_input and storing input in variable first_number___

printf("\n Enter the Second Number - ");

//__Prompting the user to enter Second Number___

scanf("%d",&second_number);

//___Reading the user_input and storing input in variable second_number___

//__Displaying the user input once again____

printf("\n\n\t Numbers before swapping :- \n\n\t\t First  - %d \n\n\t\t Second - %d", first_number, second_number);

//____________Swapping of two numbers________________

temp_number = second_number;

//__Assigning the value of second_number in a temp_number__

second_number = first_number;

//__Assigning the value of first_number to second_number___

first_number = temp_number;

//__Assigning the value in temp_nhumber to first_number___

//__Displaying the numbers after swapping___

printf("\n\n\t Numbers after swapping :- \n\n\t\t First  - %d \n\n\t\t Second - %d", first_number, second_number);

printf("\n\n________________________________________________________________________________");

getch();

return 0;

}

Follow Us on Facebook - Assignment Hub

Reverse a digit using array in C ( 5 Digit number )



Code - 

//___Program to reverse a 5 digit number___

/* There are 2 ways for reversing a number....1 is implemented below and for other

   check Reversing a number Version 2

   Logic - The first way is to extract the digits one by one and store them in an array and print the array

   Disadvantage of using this type of method is that it is space consuming i.e. requires memory

   of 5 variable */

//_________Including Header Files____________

#include<stdio.h>

#include<conio.h>

//________Included mainly for the getch() function____________

int main()
{
int number, number_digits[5], counter = 0, remainder = 0, temp_number = 0, i = 0;

//_________Variable declaration_________

printf("\n\n\t\t   _______ Reverse the 5 digit number _________\n\n\n");

printf("  Enter a 5 digit number - ");

//___Prompting the user to enter a 5 digit number____

scanf("%d", &number);

//____Reading the user inputr and storing it in variable number of type integer___

temp_number = number;

while(number != 0)

/*__Looping Construct which will keep on executing till number does not become 0 when divided by

10__ */
{
remainder = number % 10;

/*_Extracting the digit using modulus operator by gettning the remainder after dividing the

number by 10__ */

number = number / 10;

/*_Changing the value of number by assigning it the quotient obtain after dividing it by 10__ */

number_digits[counter] = remainder;

//___Assigning the digits one by one to the array elements____

counter++;
/*__Counter variable is used to count the number of digits in the original number inputted ___ */

}

if (counter != 5)

//_________Checking whether the total number of digits were 5 or not____________
{
printf("\n\n\t  ___ 5 Digit number was required ___");
}

printf("\n\n\t\t  Reverse of %d number %d entered is  - ", counter, temp_number);

for (i = 0; i <= counter - 1; i++)

//__________Looping construct to display the elements of the array___________

{
printf("%d", number_digits[i]);

}

getch();

return 0;

/*_return 0 tells the compiler that program has executed successfully without any error__ */

}

Follow Us on Facebook -  Assignment Hub

Real roots of a Quadratic Equation in C


Code -


//___________Real roots of quadratic equation...(Function Example)________

/* Quadratic equations has roots if and only if the Discriminent of a quadratic equation is greater than or equal to 0

D = b * b - 4 a * c

The formula given above is used to check whether real roots exist or not before calculation */


//____________Inlcude Header Files____________

#include<stdio.h>

#include<conio.h>

//_________Inlcuded mainly for getch() function_________

#include<math.h>

//Included mainly for the sqrt() function______

int check_roots(int a, int b, int c);


//__________Function prototype to check whether real roots exist or not_________

void roots(double discriminent, int a, int b, int c);

//_________Function prototype to find out the roots of quadratic equation____________

int main()

//_________Function from where the program execution starts_____________

{
int xsq_coefficient = 0, x_coefficient = 0, constant = 0, discriminent = 0;

printf("\n\n      _______Program will calculate the roots of a Quadratic Equation______");

printf("\n\n Quadratic Equation is in form of :- \n\n\t A (x * x) + B (x) + C = 0, where C is a constant"); //_______Message for User________

printf("\n\n\t Enter the value for A - ");

//__Prompting the user to enter the value for coefficient of X square i.e. x * x__

scanf("%d", &xsq_coefficient);

//__Reading the user input and storing it in variable xsq_coefficient______

printf("\n\t Enter the value for B - ");

//__Prompting the user to enter the value for coefficient of X ___

scanf("%d", &x_coefficient);

//_Reading the user input and storing it in variable x_coefficient__

printf("\n\t Enter the value for C - ");

//_Prompting the user to enter the value of C__

scanf("%d", &constant);

//_Reading the user input and storing it in variable constant____

discriminent = check_roots (xsq_coefficient, x_coefficient, constant);

//_____Calling the check_roots function to get the value for discriminent______

if (discriminent >= 0)

//___Checking if discriminent if +ive and greater than equal to 0, roost exist____
{
roots((double)discriminent, xsq_coefficient, x_coefficient, constant);

/*___Calling the roots function to find out and display the roots for the quadratic equation__*/
}
else
{
printf("\n\n\t\t ________Roots are not real________");
//__________If roots dont exist, message gets displayed_______________

}

printf("\n\n_______________________________________________________________________________");

getch();

return 0;
/*_Return 0 tells the compiler that this program has executed successfully without any error___*/

}

int check_roots(int a, int b, int c)
{
int discriminent = 0;

discriminent = b * b - 4 * a * c;

//_Calculating discriminent using the given formula_

return discriminent;
}

void roots(double discriminent, int a, int b, int c)
{
double x1 = 0, x2 = 0;

//__Finding the first root_____

x1 = x1 + sqrt(discriminent);

x1 = x1 - b;

x1 = x1 / (2 * a);

//___Finding the second root___

if (discriminent == 0.00)
{
x2 = x1; //___If discriminent is 0, then roots are equal_
}
else
{
x2= x2 - sqrt(discriminent);

x2 = x2 - b;

x2 = x2 / (2 * a);

}

printf("\n\n  Roots for the Quadratic Equation :- %lf, %lf",x1,x2);

//____________Displaying the value for the roots______________

}

Monday, 2 July 2012

Prime number between 1 to 300 in C


Code -


//__Program to print all prime numbers from 1 to 300._

/* A number is said to be a prime number if it is greater than 1 and has exactly 2 divisors,
one is the number itself and other is 1 For Example - Among 1 to 6, 
2-4-5 are prime numbers */

//_________Including Header Files in the program__________

#include<stdio.h>

#include<conio.h>

//__________Mainly imported for getch() Function______________

int main()

 //__________Main Function from where the program execution starts____________

{
int number = 0, counter = 0,temp_counter = 0, temp = 0, display_newline = 0;

       //__________Variable Declaration and Initialization_____

printf("\n\n\t  ___ Program will display prime number between 1 to 300 ___");

printf("\n\n\n\tPrime Numbers -  ");

for(counter = 2; counter <= 300 ; counter ++)

//________Looping construct will run from 2 to 300__________

{
number = counter;

         //____Copying the value of counter to variable named number________

temp = 0;

for (temp_counter = 1 ; temp_counter < counter ; temp_counter++)
{

/* This looping construct will work one less time the number and will
check whether the given number is divisible by any number less than the original number,
 if it is divisible a variable named as temp will be incremented by 1.
*/

if ((number % temp_counter) == 0)
{
temp++;
}
}

if (temp == 1)
/*______As mentioned at the starting the number is a prime number if it is
 divisible by 1 and number itself and in the above for loop, it is checked
 whether the number is divisible by any number between 1 and (number - 1),
 so if temp is equal to 1 then it is a prime number */

{
printf("%d, ", number);
}

}

getch();

return 0;

//__return 0 tells the compiler that program has executed successfully without any error_

}

Follow Us on Facebook - Assignment Hub

Find minimum number in an array in C


Code - 


//_Program reads 5 numbers and find the minimum out of them .... (Array Example)__

//__________Include Header Files___________

#include<stdio.h>

#include<conio.h>

//____________Mainly used for the getch() function______________

int main()

//_____This is the function from where the program execution starts____

{
int number[5], temp = 0, minimum = 0;

//_________Array index starts from 0 and runs till (Size - 1)_______________

printf("\n\n\t\t________Finding the minimum out of 5 numbers_________\n\n");

for(temp = 0; temp < 5 ; temp++)

//__________Looping construct from 0 to 4 i.e. 5 times___________

{
printf("\n  Enter the %d number - ",temp + 1);

//___________Prompting the user to enter the numbers____________

scanf("%d", &number[temp]);

//_____________Reading the numbers and adding them to array__________
}

minimum = number[0];

//__________Assuming the first number is the minimum number____________

for (temp = 1; temp < 5; temp++)
{
if (number[temp] < minimum)

//______ Checking if the other elements in the array is less than the minimun set______
{
minimum = number[temp];
}
}

printf("\n\n________________________________________________________________________________");

printf("\n\n\t\tMinimum Number :- %d", minimum);

//___________Displaying the lowest number____________

getch();

return 0;

//__Return 0 tells the compiler that program execution has been done without any errors_

}


Follow Us on Facebook -  Assignment Hub

One number raise to power another number in C ( Power Function )


Code - 


//___Program will calculate the result of one number raise to another_________

//__Pow(x,y) function also exist for the same purpose____________________


//______________Inlcude Header Files__________________

#include<stdio.h>

#include<conio.h>

//_________Function is mainly used to for getch() function__________________

int main()

/*________Main Function from where the execution starts..

.....Function return type is of Integer______*/

{

int base_number = 0 , power = 0, temp = 0, result = 1;

//__________Variable Declcaration and Initialization______________

//__Initialization is done to prevent the variable from taking garbage value__

printf("\n\n\t   ________Program to calculate one number raise to another_______");

printf("\n\n\t  Enter the base number - ");

//________Prompting the user to enter base number__________

scanf("%d", &base_number);

//_Reading the user input and storing it in an interger variable named base_number_

printf("\n\n\t  Enter the power to be calculated - ");

//________Prompting the user to enter the power of the number________

scanf("%d", &power);

for (temp = 1 ; temp <= power ; temp++)

//_______Looping construct from 1 to power__________

{
result = result * base_number;

         //_______Multiply the number that many times________

        }

printf("\n\n________________________________________________________________________________");

printf("\n\n\t  Output - %d raise to power %d is - %d",base_number, power, result);

//________Display the result of one number raise to power another number______________

printf("\n\n________________________________________________________________________________");

getch();

return 0;


}

Follow Us on Facebook - Assignment Hub

Factorial of a Number in C


Code -


//__Program will calculate the factorial of a given number (No Validation included)____



//____________________Include Header Files_________________


#include<stdio.h>

//________Header Files are also known as Preprocessor directives____________

#include<conio.h>

//________Mainly for the getch function included in program_________________

int main()

//___________This is from where the execution starts_____________________

{
int number = 0, factorial = 1, temp = 0;

//____________Variable Declaration_____________


        printf("\n\t\t\t_______Factorial of a Number_______");

printf("\n\n\t     Enter the Number - ");

//____________Prompting the user to enter the number for which to calculate

scanf("%d", &number);

//_________Reading the user input and storing the input in variable number_________

for(temp = number ; temp >= 1; temp --)
{
factorial = factorial * temp;

}

printf("\n\n\t     Factorial of %d is - %d",number,factorial);

//_______Display the final output_________

getch();

}


Follow Us on Facebook - Assignment Hub

Compare Area and Perimeter in C


Code -


//___Program to check whether the area of a rectangle is greater than its perimeter____

/* Area of rectangle = Length of rectangle * Breadth of rectangle

   Perimeter of rectangle = 2 ( Length * Breadth ) */

//_______________Including Header Files__________________

#include<stdio.h>

#include<conio.h>

//__________Header file mainly included for the getch() function__________

int main()
{
int length = 0, breadth = 0, area = 0, perimeter = 0;

//_________Variable declaration and initialization____________

printf("\n\n       _____ Program will compare the Area and Perimeter of Rectangle _____");

printf("\n\n\n  Enter the length of the Rectangle  - ");

//_________Prompting the user to enter the length of the rectangle___________

scanf("%d", &length);

//_________Reading the user input and storing it in varible length of type integer______

printf("\n\n  Enter the breadth of the Rectangle - ");

//_________Prompting the user to enter the breadth of the rectangle__________

scanf("%d", &breadth);

//_________Reading the user input and storing it in variable breadth of type integer____

area = length * breadth;

//_____________Calculating the area of the rectangle_____________________________

perimeter = 2 * ( length + breadth);

//_____________Calculating the perimeter of the rectangle________________________

if (area > perimeter)

//_____________Checking for the area being greater than the perimeter____________

{
printf("\n\n\t Area of rectangle with dimensions Length - %d and Breadth - %d is \n\n\t\t\t Greater than its Perimeter", length, breadth);
}
else if (area == perimeter)

//_____________Checking for the area being equal to the perimeter________________

{
printf("\n\n\t Area of rectangle with dimensions Length - %d and Breadth - %d is \n\n\t\t\t Equal to its Perimeter", length, breadth);
}
else

//____This part will automatically check for the area being smaller than the perimeter____

{
printf("\n\n\t Area of rectangle with dimensions Length - %d and Breadth - %d is \n\n\t\t\t Less than its Perimeter", length, breadth);
}

getch();

return 0;
//_return 0 will tell the compiler that the progrem has executed successfully without any error____

}

Follow Us on Facebook -  Assignment Hub

Check Valid Traingle in C

Code -


//_______Program will check whether the traingle is valid or not_______

/* A traingle is said to be valid if the sum of all the three angles of traingle is equal to 180 degree */

//_______Including Header Files___________

#include<stdio.h>

#include<conio.h>

//___________Inlcuded mainly for the getch() function____________

int main()
{
int first_angle = 0, second_angle = 0, third_angle = 0, sum = 0;

//_________Variable declaration and initialization__________

printf("\n\n\t\t____ Checking whether the traingle is valid or not _____");

/*____Prompting the user to enter th three angles of traingle and storing the user

input in  variables first_angle, second_angle, third_angle respectively____ */

printf("\n\n  Enter the First angle (in degrees)  - ");

scanf("%d", &first_angle);

printf("\n\n  Enter the Second angle (in degrees) - ");

scanf("%d", &second_angle);

printf("\n\n  Enter the Third angle (in degrees)  - ");

scanf("%d", &third_angle);


sum = first_angle + second_angle + third_angle ;

//_______Adding all the angles read through the user input_________

if (sum == 180)

//_______Checking for the triangle being valid_____________________

{
printf("\n\n\t\t\t _____ Traingle is valid ______");
}
else
{
printf("\n\n\t\t\t  _____ Traingle is invalid ______");
}

getch();

return 0;

/* ___return 0 tells the compiler that the program has executed successfully without

any error__ */

}

Follow Us on Facebook - Assignment Hub

Odd or Even Number in C


Code -


//_____Program will find out whether a given year is leap year or not_______

/* An year is said to be a leap year if it is completely divisible by 400 OR it is divisible by 4 not by

 100.  Hint -  Modulus operator will be used (%)  */

//__________________Including Header Files___________________

#include<stdio.h>

#include<conio.h>

//________Mainly included for the getch() function____________

int main()

//________Program execution starts from the main function_____

{
int year;

printf("\n\n\t  ___________ Program to check year for being a Leap year ___________");

printf("\n\n Enter the year - ");

//___________Prompting the user to enter a year____________

scanf("%d", &year);

//____Reading the user input and storing that input in variable year of type Integer_____

if (((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0)))

//_____Checking the year for being a leap year______

{
printf("\n\n\t\t\t__________ %d is a leap year __________", year);

//_____This statement will get executed if the year entered is a leap year_____

}
else
{
printf("\n\n\t\t     _________ %d is not a leap year _________", year);

//_____This statement will get executed if the year entered is not a leap year_____

}

getch();

return 0;

//_return 0 tells the compiler that program has executed successfully without errors__
}

Follow us on Facebook - Assignment Hub

Checking for Leap Year in C


Code -


//______Program will find out whether a given year is leap year or not_________

/* An year is said to be a leap year if it is completely divisible by 400 OR it is divisible by 4 not by 100

Hint -  Modulus operator will be used (%)  */

//__________________Including Header Files___________________

#include<stdio.h>

#include<conio.h>

//________Mainly included for the getch() function____________

int main()

//________Program execution starts from the main function_____

{
int year;

printf("\n\n\t  ___________ Program to check year for being a Leap year ___________");

printf("\n\n Enter the year - ");

//___________Prompting the user to enter a year____________

scanf("%d", &year);

//__Reading the user input and storing that input in variable year of type Integer__

if (((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0)))

       //_____Checking the year for being a leap year______
{
printf("\n\n\t\t\t__________ %d is a leap year __________", year);

      //_____This statement will get executed if the year entered is a leap year_____

        }
else
{
printf("\n\n\t\t     _________ %d is not a leap year _________", year);

//_____This statement will get executed if the year entered is not a leap year_____

}

getch();

return 0;

       /*_return 0 tells the compiler that program has executed successfully without errors___*/

}

Follow us on Facebook - Assignment Hub

Calculate profit and loss in C













Code -


//____Program will calculate the profit and loss based on selling price and cost price_____


/* The user of the system will input the Cost Price and Selling Price of an item and based on the input the program will calculate whether the shopkeeper had made a  profit or loss

If Selling Price - Cost Price > 0
Profit is dere
If Selling Price - Cost Price = 0
No Profit No Loss situation
If Selling Price - Cost Price < 0
Loss has incurred

*/

//_______________Include Header Files______________

#include<stdio.h>

#include<conio.h>

//___________Mainly included for the getch() function___________________

int main()

//___________Main is the fucntion from where the program execution starts_______________

{
float cost_price = 0, selling_price = 0;

//___________Variable Declaration and Initialization___________

double pro_loss = 0;

printf("\n\n\t __________Program will calculate Profit or Loss__________");

printf("\n\n\n Enter the Cost Price    - $ ");

//___________Prompting the user to enter the cost price of the item______________

scanf("%f",&cost_price);

//___________Reading the user input and storing it in a variable of type float___

printf("\n\n Enter the Selling Price - $ ");

//___________Prompting the user to enter the selling price of the item___________

scanf("%f",&selling_price);

//___________Reading the user input and storing it in a variable of type float___

pro_loss = selling_price - cost_price;

/*___Calculating the amount that is left after subtracting cost price from selling price_____*/

if (pro_loss > 0)

//___________Checking for profit__________

{
printf("\n\n\t\t   _________Profit has incurred_________");
}
else if (pro_loss == 0)
{
printf("\n\n\t\t   _________No Profit, No Loss_________");
}
else

//__________Checking for Loss_____________

{
printf("\n\n\t\t    _________Loss has incurred_________");
}

printf("\n\n\n\t\t\t     Amount - $ %.2lf", pro_loss);

//__________Displaying the amount_________

printf("\n\n________________________________________________________________________________");

getch();

return 0;
/*___Return 0 tells teh compiler that program has executed successfully without any error____ */

}