C

Tuesday, 29 August 2017

C Program To Find First 10 Multiple of a Number Using For Loop

#include<stdio.h>
main()
{
int num, i=1;
clrscr();
printf("Enter the number whose multiple you want to see : ");
scanf("%d",&num);
for(i=1;i<=10;i++)
{
printf("%4d",i*num);
}
getch();
}


C Program To Find Sum of a First 10 Natural Numbers Using For Loop

#include<stdio.h>
main()
{
int i,sum=0;
clrscr();
for(i=1;i<=10;i++)
{
sum=sum+i;
}
printf("The total of first 10 natural number is : %d",sum);
getch();
}


C Program To Find First 10 Multiples of a Number Using Do-While Loop

#include<stdio.h>
main()
{
int num,i=1;
printf("Enter the number whose multiple you want");
scanf("%d",&num);
do
{
printf("%3d",i*num);
i++;
}while(i<=10);
getch();
}


C Program To Find Sum of First 10 Natural Numbers Using Do-While Loop.

#include<stdio.h>
main()
{
int num=1, sum=0;
clrscr();
do
{
sum +=num;
num +=1;
}while(num<=10);
printf("The total of first 10 natural numbers is: %d",sum);
getch();
}


C Program To Find The First 10 Multiples of a Number Using While Loop.

#include<stdio.h>
main()
{
int num,i=1;
clrscr();
printf("Enter the number whose multiple you want");
scanf("%d",&num);
while(i<=10)
{
printf("%3d",i*num);
i++;
}
getch();
}


C Program To Find Sum of First 10 Natural Numbers Using While Loop.

#include<stdio.h>
main()
{
int num=1,sum=0;
clrscr();
while(num<=10)
{
sum +=num;
num +=1;
}
printf("The sum of first 10 natural number is : %d",sum);
getch();
}


Monday, 28 August 2017

Program To Check Whether A Number is Odd or Even.

#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter the integer value\n");
scanf("%d",&n);
if(n%2==0)
printf("The value is even");
else
printf("The value is odd");
}

Program To Check Whether A Number Is Prime or Not.

#include<stdio.h>
void main()
{
int n,i;
clrscr();
printf("Enter the Number :");
scanf("%d",&n);
i=2;
while(i<=n-1)
{
if(n%i==0)
{
printf("Number is not a prime number\n");
break;
}
i=i+1;
}
if(i==n)
printf("Number is a prime number");
}


Sunday, 27 August 2017

Program To Print All Even Numbers

#include<stdio.h>
#include<conio.h>
void main(void)
{
int i=2;
clrscr();
while(i<=10)
{
if(i%2==0)
{
printf("\nThe value is =%d",i);
}
i++;
}
}



Program To Calculate Customers Telephone Bill

#include<stdio.h>
void main()
{
int units, custno;
float charge;
clrscr();
printf("Enter customer number and unit consumed\n");
scanf("%d%d",&custno,&units);
if(units<=200)
charge=0.5*units;
else if(units<=400)
charge=100+0.25*(units-200);
else if(units<=600)
charge=230+0.8*(units-400);
else
charge=390+(units-600);
printf("Customer no:%d consumed :%d units\n",custno,units);
printf("Total bill amount is : %.2f\n",charge);
}



Sunday, 20 August 2017

Program to Perform all the Arithmetic Operations

#include<stdio.h>
main()
{
int first,second,Add,Sub,Mul;
float Div;
clrscr();
printf("Enter two integer numbers\n");
scanf("%d%d",&first,&second);
Add=first+second;
Sub=first-second;
Mul=first*second;
Div=first/second;
printf("Sum=%d\n",Add);
printf("Difference=%d\n",Sub);
printf("Multiplication=%d\n",Mul);
printf("Division=%f\n",Div);
return 0;
}



Friday, 18 August 2017

Program to Calculate Simple Interest and Compound Interest

#include<stdio.h>
#include<math.h>
int main()
{
float p,q,r,smpi,cmpi;
int  n;
clrscr();
printf("Enter the value of principle p = ");
scanf("%f",&p);
printf("Enter the value of rate r = ");
scanf("%f",&r);
printf("Enter the value of period in year n = ");
scanf("%d",&n);
smpi=((p*r*n)/100);
printf("The Simple Interest is=%f \n",smpi);
q=1+(r/100);
cmpi=p*pow(q,n)-p;
printf("The Compound Interest is=%f \n",cmpi);
return 0;
getch();
}


OUTPUT:-


Program To Perform Logical Operator

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter the value of a,b and c\n");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(b>c))
printf("\na is greater than b =%d",a);
else
printf("\nb is greater than a =%d",b);
if(a>c)
printf("\na is greater value than c =%d",a);
else
printf("\nc is greater value than a =%d",c);
if((a==b)||(a==c))
printf("\na value is equal to b");
else
printf("\nvalues are not equal");
getch();
}                 

Program To Perform Relational Operator

#include<stdio.h>
#include<conio.h>
main()
{
int x,y,z;
clrscr();
printf("Enter the values of x,y and z\n");
scanf("%d%d%d,",&x,&y,&z);
if(x==y)
printf("\nBoth the values are same =%d",x,y);
if(x>y)
printf("\nThe value of x is greater =%d",x);
else
printf("\nThe value of y is greater =%d",y);
if(y!=z)
printf("\nThe value of y is not equal to =%d",y);
getch();
}

Friday, 4 August 2017

SWAPPING OF TWO VALUES WITHOUT USING THIRD VARIABLE

#include<stdio.h>
#include<conio.h>
main()
{
int a=8, b=12;
clrscr();
printf("Before swap of two numbers a=%d b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swap of numbers a=%d b=%d",a,b);
getch();
}

Write a program to draw a circle using mid-point circle drawing algorithm.

#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) {         ...