C programs for Practice || Free Code Center

Compound of interest in C

#include<stdio.h>

int main()

{

    double p,r,n,ci,a;

    printf(“Enter a  Principal ,Rate of Interest and Time(y)”);

    scanf(“%lf %lf %lf”,&p,&r,&n);

    a=pow (1+r/100,n)*p;

    ci=a-p;

    printf(“Compound of interest is %.3lf”,ci);//c programs for practice

}

Convert day in the year

#include <stdio.h>

int main()

{

    double days,year;

    printf(“Enter days =”);

    scanf(“%lf”,&days);

    year=days/365;

    printf(“Total year is=%.3lf”,year);

}

Calculate and Print the Cube of Numbers in C

#include<stdio.h>

void main ()

{

    int i,cube;

    scanf(“%d”,&i);

    for(int i=1;i<=5;i++){

            cube=i*i*i;

        printf(“\nnumber is %d and  cube of the %d is :%d”,i,i,cube);

    }

}

Find and Sum All Numbers Divisible by 9 Between 100 and User Input.

#include<stdio.h>

void main ()

{

    int i,n,disvi=1,sum=0;

    scanf (“%d”,&n);

    printf(“Numbers between 100 and 200:”);

    for (i=100;i<=n;i++){

        if(disvi=(i%9==0)){

printf(” %d “,i);

        sum=i+sum;

        }

    }

    printf(“\nThe sum:%d”,sum);

}

 Find the area of an equilateral

#include<stdio.h>

int main()

{

    double a,area;

    printf(“Enter lenght of sides:”);

    scanf(“%lf”,&a);

    area=0.8660*a*a;

    printf(“Area of equilateral is:%.3lf”,area);

    return 0;

}

 Find the factorial of N numbers

#include<stdio.h>

void main ()

{

    int i,n,factorial=1;

    printf(“Enter a number :”);

    scanf(“%d”,&n);

    for (i=1;i<=n;i++){

        factorial=factorial*i;

    }

    printf(“The factorial of 5 is:%d”,factorial);

}

Farhenheit to centigrade

#include<stdio.h>

int main()

{ double f,c;

 printf(“Enter farhenheit =”);

 scanf(“%lf”,&f);

 f= 9*c/5+32;

 printf(“The value of centigrade is =%.3lf”,f);

}

Find the simple interest in C

#include<stdio.h>

int main ()

{

    double p,r,t,si;

    printf(“Enter a  Principal ,Rate of Interest and Time(y)= “);

    scanf(“%lf %lf %lf”,&p,&r,&t);

    si =p*r*t;

    printf(“This is your simple interest%.3lf”,si);

return 0;

}

Find the LCM in C

#include <stdio.h>

int main()

{

    int i, num1, num2, max, lcm=1;

    printf(“Enter any two numbers to find LCM: “);

    scanf(“%d%d”, &num1, &num2);

    max = (num1 > num2) ? num1 : num2;

    i = max;

    while(1)

    {

        if(i%num1==0 && i%num2==0)

        {

            lcm = i;

            break;

        }

        i=i+ max;

    }

    printf(“LCM of %d and %d = %d”, num1, num2, lcm);

    return 0;

}

Leap Year check program in C

#include<stdio.h>

int main ()

{

int num;

int y;

printf(“enter the year to check:”);

scanf(“%d%d”,&y,&num);

 for(y==1;y<=num;y++){

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

        printf(“%d is leap year”,y);}

 }

}

Factorial Program in C || What is the factorial of 100 in C

Leave a Comment