Skip to main content

Posts

Showing posts with the label Advanced C

(1+2+3.....n) Sum of n natural numbers, (1^2 + 2^2+3^2 ...... n^2)Sum square of n natural numbers, Sum cube of n natural numbers program in C language .

   Natural numbers program in c language                  H ow to make  (1+2+3.....n) Sum of n natural numbers, (1^2 + 2^2+3^2 ...... n^2)Sum square of n natural numbers, Sum cube of n natural numbers program in C language. Then today we will know about it through this program ...    Sum of n natural numbers            The Sum of n natural number formula are 1+2+3+....n = n(n+1)/2=(n^2+n)/2. The math.h header file is used in this program because the pow() function is defined in this header file. The function pow() syntax is double pow(double a , double b).   The double is a data type in c language and it's also defined as %lf for input. In this program add= (k+x)/2 where are k=n^2 ,x=n. /*SUM OF N NATURAL NUMBERS*/ #include"stdio.h" #include"math.h" int main() { double x,y=2; printf("ENTER THE NATURAL NUMBER:"); scanf("%lf",&x); double n=pow(x,y); int add=(n+x)/2; printf("SUM OF N NATURAL NUMBER:%d",add); } Output i

Age calculating through date of birth program in C language

DATE OF BIRTH PROGRAM IN C LANGUAGE          Today's date - your date of birth = your current age  There are fifth condition are happening.. @1.IF today date 13.7.2021 and date of birth 15.9.2001 age are (2021-2001).(7-9).(13-15) = 20.-2.-2   but it's wrong real age will be 19year.9month.28days .Then first condition will be (days < 0)&&(month<0) @2.IF today date 13.7.2021 and date of birth 12.9.2001 age are(2021-2001).(7-9).(13-12) = 20.-2.1 but it's wrong real age will be 19 year . 10 month . 1 days .Then  second condition will be (days>0)&&(month<0). @3.IF today date 13.7.2021 and date of birth 13.9.2001 age are(2021-2001).(7-9).(13-13) = 20.-2.0 but it's wrong real age will be 19 year . 10 month . 0days .Then  third condition will be (days==0)&&(month<0). @4.IF today date 13.7.2021 and date of birth 13.9.2001 age are(2021-2001).(7-9).(13-13) = 20.1.0 but it's wrong real age will be 19 year . 10 month . 0days .Then  fourth