Saturday, December 31, 2011

Print following pattern in Continuous number 'C'.


  1
  23
  456
  78910

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k=1;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);

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

{

for(j=1;j<=i;j++)

{

     printf("%d",k);

     k++;
}
printf("\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:4


1
23
456
78910
*/

Find out Ascii of given character in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
char a;
int b;
clrscr();
printf("Enter the character:");
scanf("%c",&a);
printf("ASCII value of character is:%d",a);
getch();
}
/*========================================================================
OUTPUT
Enter the character:a
ASCII value of character is:97
*/

Print following pattern in 'C'


1
12
123
1234

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=1;j<i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:5


1
12
123
1234
*/


Display reverse of natural number in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,rev=0,n,a;
clrscr();
printf("Enter the number:");
scanf("%d",&n);


while(n>0)
{       a=n%10;
rev=(rev*10)+a;
n=n/10;


}


printf("Reverse of given number is:%d",rev);
getch();
}
/*=======================================================================
OUTPUT
Enter the number:1234
Reverse of given number is:4321
*/

Find the number is palimdrome or not in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,pal=0,a,m;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
m=n;
while(n>0)
{
   a=n%10;
   pal=(pal*10)+a;
   n=n/10;
}
if(m==pal)
{
printf("Given number is palimdrome");
}
else
{
printf("Given number is not palimdrome");
}
getch();
}
/*=======================================================================
OUTPUT
Enter the number:333
Given number is palimdrome
*/

Find whether natural number is prime or not. in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,count=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
i=1;
while(i<=n)
{
if(n%i==0)
{
count++;
}
i=i+1;
}
if(count<=2)
{
printf("It is a prime number");
}
else
{
printf("It is not a prime number");
}
getch();
}
/*======================================================================
OUTPUT
Enter the number:5
It is a prime number
*/

Find sum of even and odd number from n natural number in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,sumeven=0,sumodd=0,n;
clrscr();
printf("Enter the number n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2==0)
{

                   sumeven
=
sumeven + i








else
{
sumodd=sumodd+i;
}
}
printf("sum of even number is:%d",sumeven);
printf("\nsum of odd number is:%d",sumodd);
getch();
}
/*=======================================================================
OUTPUT
Enter the number n:4
sum of even number is:6   // 2 + 4
sum of odd numbe is:4  // 1 + 3
*/

Matrix multiplication table in 'C'

Example



#include<stdio.h>
#include<conio.h>


void main()
{
int row,column,y,n,p,x;
clrscr();
printf("\nENTER THE NUMBER OF ROW = ");
scanf("%d",&n);
x=n;
row=1;
printf("\n\tMULTIPLICATION TABLE\n");
printf("-----------------------------\n");
do
{
column=1;
do
{
y=row*column;
printf("%4d",y);
column=column+1;
}
while(column<=n);
printf("\n");
row=row+1;
  }
   while(row<=x);


   printf("------------------------------\n");
   getch();
}


/*========================================================================
OUTPUT
ENTER THE NUMBER OF ROW = 5


MULTIPLICATION TABLE
-----------------------------
  1   2   3   4   5
  2   4   6   8  10
  3   6   9  12  15
  4   8  12  16  20
  5  10  15  20  25
------------------------------    */

Find sum of square of n natural number in 'C'

Example



#include<stdio.h>
#include<conio.h>


void main()

{

int n,i,sum=0;
clrscr();
printf("Enter the number :");
scanf("%d",&n);
for(i=1;i<=n;i++)
 {
sum=sum+(i*i);
}
printf("sum of square of n natural number is:%d",sum);


 getch();
}
/*========================================================================
OUTPUT
Enter the number :2
sum of square of n natural number is:5
*/

Find vowel,constant or other character in a given Character in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int a;
char c;


clrscr();
printf("Enter the char u want:");
scanf("%c",&c);
if(c=='a'|| c=='e' || c=='i' || c=='o' || c=='u')
{
a=1;
 }
else if(c=='1'|| c=='2' || c=='3' || c=='4' || c=='4')
{
a=2;
}
else
{
a=3;
}
switch(a)
{
case 1:
printf("Character is vowels");
break;
case 2:
printf("\nCharacter is constant");
break;
case 3:
printf("\nCharacter is charater");
break;
default:
printf("Enter the character");
}
getch();


}
/*=========================================================================
OUTPUT
Enter the char u want:4


Character is constant */

Matrix multiplication table. in 'C'

Example



#include<stdio.h>
#include<conio.h>


void main()
{
int i=1,n;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
printf("\nN\tN^2\tN^3");
while(i<=n)
{
printf("\n%d \t%d \t%d",i,(i*i),(i*i*i));
i++;
}
getch();
}
/*=================================================================
OUTPUT
Enter the number:3
                                                                                
N       N^2     N^3                                                             
1       1       1                                                               
2       4       8                                                               

Calculator in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int no;
float a,b,c;
clrscr();
printf("Enter the value of a:");
scanf("%f",&a);
printf("Enter the value of b:");
scanf("%f",&b);
printf("=======================OPERATION ARE===================\n");
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n======================================================\n");
printf("Enter the operation you want to do:");
scanf("%d",&no);
switch(no)
{
case 1:
{
      c=a+b;
      printf("\nAddition of two number is:%.f",c);
break;
}
case 2:
{
if(a>b)
{
c=a-b;
}
else
{
c=b-a;
}
printf("\nSubtraction of two number is:%f",c);
break;
}
case 3:
{
c=a*b;
printf("\nMultiplication of two number is:%.2f",c);
break;
}
case 4:
{
if(a>b)
{
c=a/b;
}
else
{
c=b/a;
}
printf("\nDivision of two number is:%.2f",c);
break;
}
default:
printf("Enter the proper number");


}
getch();
}
/*========================================================================
OUTPUT
Enter the value of a:3
Enter the value of b:4
=======================OPERATION ARE===================


1.Addition
2.Subtraction
3.Multiplication
4.Division
======================================================
Enter the operation you want to do:2


Subtraction of two number is:1.000000 */

Find Factorial of given number in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int fact=1,n,i;
clrscr();
printf("Enter the number::");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial of given number is:%d",fact);
getch();
}
/*===========================================================================
OUTPUT
Enter the number::5
Factorial of given number is:120
*/

Find sum of Entered number in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("Enter the number :");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
sum=sum+i;
}
printf("Total sum of given number is=%d",sum);
getch();
}
/*============================================================
OUTPUT
Enter the number :5
Total sum of given number is=10 */



Find amount of unit consumed in Electricity in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int unit;
float amt;
clrscr();
printf("Enter the unit consumed:");
scanf("%d",&unit);
if(unit>0 && unit<=200)
{
amt=unit*0.50;
}
else if(unit>=201 && unit<=400)
{
amt=(unit*0.35)+100;
}
else if(unit>=401 && unit<=600)
{
amt=(unit*0.80)+230;
}
else if(unit>=601)
{
amt=(unit*1)+390;
}
else
printf("Enter proper unit:");
printf("\nAmount of unit consumed=%.3f",amt);
getch();
}
/*========================================================================
OUTPUT
Enter the unit consumed:500
Amount of unit consumed:630.000
=========================================================================*/

Find percentage of given five subject in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,m4,m5,sum=0;
float per;
clrscr();
printf("Enter marks m1:");
scanf("%d",&m1);
printf("Enter marks m2:");
scanf("%d",&m2);
printf("Enter marks m3:");
scanf("%d",&m3);
printf("Enter marks m4:");
scanf("%d",&m4);
printf("Enter marks m5:");
scanf("%d",&m5);
sum=m1+m2+m3+m4+m5;
per=sum/5;
printf(" Sum of marks is=%d",sum);
printf("\n Percentage of marks is=%.2f",per);
if(m1<100 && m2<100 && m3<100 && m4<100 && m5<100)
{
if(m1>35 && m2>35 && m3>35 && m4>35 && m5>35)
{
if(per>=70)
{
printf("\nClass=Distinction");
}
else if(per>=60 && per<70)
{
printf("\nClass=First");
}
else if(per>=50 && per<60)
{
printf("\nClass=Second");
}
else if(per>=35 && per<50)
{
printf("\nClass=Pass");
}
       }   else
       {
if((m1<35 && m2<35) || (m2<35 && m3<35) || (m3<35 && m4<35) || (m4<35 && m5<35) || (m5<35 && m1<35) || m1<35 || m2<35 || m3<35 || m4<35 || m5<35)
{
printf("\nClass=ATKT");
}
}
}else
printf("\nEnter valid marks");


 getch();
}
/*=============================================================================================================
OUTPUT
Enter marks m1:44
Enter marks m2:55
Enter marks m3:66
Enter marks m4:55
Enter marks m5:66
Sum of marks is:286
Percentage of marks is:57.00
class=second
==============================================================================================================*/

Find greater no from given three number in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int no1,no2,no3;
clrscr();
printf("Enter no1:");
scanf("%d",&no1);
printf("Enter no2:");
scanf("%d",&no2);
printf("Enter no3:");
scanf("%d",&no3);
if(no1>no3 || no2>no3)
{
if(no1>no2 )
{
printf("Number no1 is greater:=%d",no1);
}
else
{
printf("Number no2 is greater:=%d",no2);
}
}
else
{
printf("Number no3 is greater:=%d",no3);
}
getch();
}
/*==========================================================================
OUTPUT
Enter no1=20
Enter no2=30
Enter no3=40
Number no3 is greater:=40*/

Check whether a given number is even or odd in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("Enter a no:");
scanf("%d",& n);
printf("\n=================ODD && EVEN=================\n");
if(n%2==0)
{
printf("\nNumber is even");
}
else
{
printf("\nNumber is odd");
}
getch();
}
/*=======================OUTPUT===========================
Enter a no:2
Number is even
=============================================================*/

Find gross salary in 'C'

Example




#include<stdio.h>
#include<conio.h>
void main()
{
float bs,hra,da,pf,gs;
clrscr();
printf("Enter basic salary:");
scanf("%f",&bs);
hra=0.125*bs;
da=0.10*bs;
pf=0.025*bs;
gs=bs+hra+da-pf;
printf("\n========GROSS SALARY OF GIVEN ALLOWANCE===============\n");
printf("\nBasic salary        =%.2f",bs);
printf("\nHouse rent allowance=%.2f",hra);
printf("\nDearness allowance  =%.2f",da);
printf("\nProvisional fund    =%.2f",pf);
printf("\n=======================================\n");
printf("\nGross salary        =%.2f",gs);
getch();
}
/*=============================================================================
OUTPUT
Enter basic salary:1000
                                                                                
========GROSS SALARY OF GIVEN ALLOWANCE===============                          
                                                                                
Basic salary        =1000.00                                                    
House rent allowance=125.00                                                     
Dearness allowance  =100.00                                                     
Provisional fund    =25.00                                                      
=======================================                                         
                                                                                
Gross salary        =1200.00   */



Find celcius from given fahrenhite in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
float fahren,celc;
clrscr();
printf("Enter fahrenhite:");
scanf("%f",&fahren);
celc=(fahren - 32.0)/1.8;
printf("\n==========FAHRENHITE TO CELCIUS============\n");
printf("\nCelcius=%.2f",celc);
getch();
}
/*==============OUTPUT===============================
Fahrenhite=97
Celcius=36.7
=====================================================*/

Find month and days of given days in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int mth,day,d1;
clrscr();
printf("Enter days of your choice:");
scanf("%d",&d1);
day=d1%30;
mth=d1/30;
printf("\n========DAYS && MONTH==========\n");
printf("\nMonth =%d",mth);
printf("\nDays  =%d",day);
getch();
}
/*=====================================================================
OUTPUT
Enter days of your choice:35


========DAYS && MONTH==========


Month =1
Days  =5  */

Find area and circumference of circle in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
float r;
float area,circum,p=3.14;
clrscr();
printf("Enter radius of circle:");
scanf("%f",&r);
area=(p*r*r);
circum=(2*p*r);
printf("\n========Area and circumference of circle==========\n");
printf("\nArea         =%.2f",area);
printf("\nCircumference=%.2f",circum);
getch();
}
/*==========================================================================
OUTPUT
Enter radius of circle:4
                                                                                
========Area and circumference of circle==========                              
                                                                                
Area         =50.24                                                             
Circumference=25.12 */