Showing posts with label C programming. Show all posts
Showing posts with label C programming. Show all posts

Monday, May 23, 2016

C program to determine whether a year is a leap year

Program
 #include<stdio.h>
main()
{
int a;
printf("enter a year :\n");
scanf("%d",&a);
if(a%4==0)
{
printf("it is a leap year");
}
else
{
printf(" it is not a ;eap year");
}
}

Output
 enter a year:
2016
it is a leap year

Cprogram for swapping two numbers using temporary variable

Program
 #include<stdio.h>
main()
{
int a,b,t;
printf("enter two numbers:\n");
scanf("%d%d",&a,&b);
t=a;
a=b;
b=t;
printf("swap values are %d and %d",a,b);
}

Output
enter two numbers:
5 6
swap values are 6 and 5

C program for calculating compound interest

Program
#include<stdio.h>
#include<math.h>
main()
{
float p,r,n,ci;
printf("enter principle,rate,no.of years :\n");
scanf("%f%f%f",&p,&r,&n);
ci=p*(pow((1+r/100),n)-1);
printf("compound interest is:%f",ci);
}

Output
 enter principle,rate,no.of years:
4.2 1.2 3.0
compound interest is:1.036434

A program for calculating simple interest

Program
#include<stdio.h>
main()
{
int p,t,r;
float si;
printf("enter the values of p,t,r: \n");
scanf("%d%d%d",&p,&t,&r);
si=(p*t*r)/100;
printf("simple interest is :%f",s);
}

Output
 enter the values of p,t,r
20 30 40
simple interest is:240.000000

Friday, May 20, 2016

C program for finding a number is even or odd

Program
#include<stdio.h>
main()
{
int a;
printf("enter a number: \n");
scanf("%d",&a);
if(a%2==0)
{
printf("a is even \n");
}
else
{
printf("a is odd \n");
}

Output
enter a number:
5
a is odd

Thursday, May 19, 2016

Program for grestest of three numbers

Program
 #include<stdio.h>
main()
{
int a,b,c;
printf("enter the values of a,b and c \n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
printf("a is greatest \n");
}
else if(b>a&&b>c)
{
printf("b is greatest \n");
}
else
{
printf("c is greatest \n");
}
}

Output
 enter the values of a,b and c:
1 2 3
c is greatest

C program for finding greatest of two numbers

Program
 #include<stdio.h>
main()
{
int a,b;
printf("enter the values of a and b: \n");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("a is greatest");
}
else
{
printf("b is greatest");
}
}

Output
 enter the values of a and b:
6 4
a is greatest

A c program for type casting

Program
#include<stdio.h>
main()
{
int a,b;
float c;
printf("enter the values of a and b: \n");
scanf("%d%d",&a.&b);
c=(float)a/b;
printf("type casted value is:%f",c);
}

Output
enter the values of a and b:
4 6
type casted value is:0.666666
 

A c program for division of two numbers

Program
#include<stdio.h>
main()
{
int a,b,ratio;
printf("enter the values of a and b: \n");
scanf("%d%d",&a,&b);
ratio=a/b;
printf("division is %d",ratio);
}

Output
enter the values of a and b
6 2
division is 3 

A C program for difference of two numbers

Program
#include<stdio.h>
main()
{
int a,b,diff;
printf("enter the values of a and b: \n");
scanf("%d%d",&a,&b);
diff=a-b;
printf("difference is:%d",diff);
}

Output
enter the vales of a and b:
5 3
difference is:2

A program for multiplication of two numbers

Program
#include<stdio.h>
main()
{
int a,b,product;
printf("enter the values of a and b: \n");
scanf("%d%d",&a,&b);
product=a*b;
printf("product is:%d",product);
}

Output
enter the values of a and b:
3 5
product is:15

Wednesday, May 18, 2016

SUM OF TWO NUMBERS

Program
 #include<stdio.h>
main()
{
int a,b,sum;
printf("enter the values of a and b: \n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum=%d",sum);
}

Output
enter the values of a and b:5 6
sum=11