Posts

Equation of a Line

Finding the equation of a Line Given Two End Points Write a program for finding the equation of a Line Given Two End Points (x1,y1) and (x2, y2) The equation for a line is Y = MX + C Where M = Slope of a Line and C = Intercept To Find the slope of a line slope = (y2 - y1) / (x2 - x1) To Find the intercept of the line, intercept = y1 - (slope) * x1 which would be same as, intercept = y2 - (slope) * x2 Input/Output: Program to find the equation of a line given two end points Enter X1: 2 Enter Y1: 3 Enter X2: 5 Enter Y2: 7 Equation of the line with end points (2, 3 and (5, 7) : Y = 1.33333X +0.333333

Find 1st three (3) Armstrong Number

Write a program to find 1 st three (3) Armstrong Number starting from 1 Hints: The condition for Armstrong number is, Sum of the cubes of its digits must equal to the number itself. For example, 407 is given as input. 4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an Armstrong number.

Program to built the pattern

Write a program to built the below pattern. ****** ***** **** *** ** * ** *** **** ***** ****** 1 12 123 1234 12345 123456 12345 1234 123 12 1

Print 1st 30 Perfect numbers starting from 0 and calculate sum

Write a C program to Print 1st 30 Perfect numbers starting from 0 and calculate sum. Hints: Today the usual definition of a perfect number is in terms of its divisors, but early definitions were in terms of the 'aliquot parts' of a number. An aliquot part of a number is a proper quotient of the number. So for example the aliquot parts of 10 are 1, 2 and 5. These occur since 1 = 10 / 10 , 2 = 10 / 5 , and 5 = 10 / 2 . Note that 10 is not an aliquot part of 10 since it is not a proper quotient, i.e. a quotient different from the number itself. A perfect number is defined to be one which is equal to the sum of its aliquot parts. The four perfect numbers 6, 28, 496 and 8128 seem to have been known from ancient times and there is no record of these discoveries. 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14, 496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064 If as many numbers as we please beginning from

Check whether the sum of all printed prime numbers are equal to the given input or not?

Image
Write a program to get a range from user and give a list of prime numbers up to that number. And check whether the sum of all printed prime numbers are equal to the given input or not? Sample Input: 10 Sample Output: Prime list: 1, 2, 3, 5, 7 The sum is: 18 The sum is not equal to 10 Hints: A Prime Number can be divided evenly only by 1, or itself. Example: 5 can only be divided evenly by 1 or 5, so it is a prime number. But 6 can be divided evenly by 1, 2, 3 and 6 so it is NOT a prime number (it is a composite number).   Source Code: #include<stdio.h> int main() {      int i, num, p, n, sum=0 ;      printf (" \n Enter the range :");      scanf ( " %d ", &n);      printf (" \n Prime list : ");      for(num =1; num <=n; num++)      {            p =1;                 for(i=2; i<= num/2; i++)                    {                         if ( num % i= =0)