Wednesday, 29 October 2014

PYRAMID STRUCTER



PYRAMID STRUCTER



1.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++)
{
if((i+j)%2==0)
printf("1 ");
else
printf("0 ");
}
printf("\n");
}
getch();
}


OUTPUT:
1
0 1
1 0 1



2.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k=1;
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",k);
k++;
}
printf("\n");
}
getch();
}

OUTPUT:
1
2 3
4 5 6


3.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=4;i>=1;i--)
{
for(j=i;j>=1;j--)
printf("%d ",j);
printf("\n");
}
getch();
}

OUTPUT:
4 3 2 1
3 2 1
2 1
1




4.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf("* ");
printf("\n");
}
getch();
}

OUTPUT:
*
* *
* * *
* * * *
* * * * *


MULTIPLICATION TABLE




MULTIPLICATION TABLE






/*MULTIPLICATION TABLE*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
printf("multiplication table of %d\n",i);
for(j=1;j<=10;j++)
{
k=i*j;
printf("%d %d %d",i,j,k);
printf("\n");
}
printf("\n");
}
getch();
}

OUTPUT:
multiplication table of 1
1 1 1
1 2 2
1 3 3
1 4 4
1 5 5
1 6 6
1 7 7
1 8 8
1 9 9
1 10 10

multiplication table of 2
2 1 2
2 2 4
2 3 6
2 4 8
2 5 10
2 6 12
2 7 14
2 8 16
2 9 18
2 10 20

multiplication table of 3
3 1 3
3 2 6
3 3 9
3 4 12
3 5 15
3 6 18
3 7 21
3 8 24
3 9 27
3 10 30

multiplication table of 4
4 1 4
4 2 8
4 3 12
4 4 16
4 5 20
4 6 24
4 7 28
4 8 32
4 9 36
4 10 40

multiplication table of 5
5 1 5
5 2 10
5 3 15
5 4 20
5 5 25
5 6 30
5 7 35
5 8 40
5 9 45
5 10 50


Convert octal number to binary number



Convert octal number to binary number



/*WAP to convert octal to binary*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int oct,dec=0,d,t=0,bin=0,r=1;
clrscr();
printf("enter the octal number:");
scanf("%d",&oct);
while(oct!=0)
{
d=oct%10;
dec=dec+d*pow(8,t);
t++;
oct=oct/10;
}
while(dec!=0)
{
d=dec%2;
bin=bin+(d*r);
r=r*10;
dec=dec/2;
}
printf("the binary number is %d",bin);
getch();
}

OUTPUT:
enter the octal number:12

the binary number is 1010

Sum of digit of a given number


Sum of digit of a given number




/*WAP to find out the sum of digit of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,r=0;
clrscr();
printf("enter the number:");
scanf("%d",&n);
while(n>0)
{
d=n%10;
r=r+d;
n=n/10;
}
printf("sum of digit is %d",r);
getch();
}

OUTPUT:
enter the number:123

sum of digit is 6

Convert the binary number to decimal number



 Convert the binary number to decimal number





/*WAP to convert the binary number to  decimal number*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int bin,dec=0,d,t=0;
clrscr();
printf("enter the binary number:");
scanf("%d",&bin);
while(bin!=0)
{
d=bin%10;
dec=dec+d*pow(2,t);
t++;
bin=bin/10;
}
printf("the decimal number is %d",dec);
getch();
}

OUTPUT:
enter the binary number:1111

the decimal number is 15

Convert the decimal number to binary number



Convert the decimal number to binary number




/*WAP to convert the decimal number to binary number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int dec,bin=0,d,t=1;
clrscr();
printf("enter the decimal number:");
scanf("%d",&dec);
while(dec!=0)
{
d=dec%2;
bin=bin+(d*t);
t=t*10;
dec=dec/2;
}
printf("the binary number is %d",bin);
getch();
}

OUTPUT:
enter the decimal number:15

the binary number is 1111

Convert the decimal number to octal number


Convert the decimal number to octal number




/*WAP to convert the decimal number to octal number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int dec,oct=0,d,t=1;
clrscr();
printf("enter the decimal number:");
scanf("%d",&dec);
while(dec!=0)
{
d=dec%8;
oct=oct+(d*t);
t=t*10;
dec=dec/8;
}
printf("the octal number is %d",oct);
getch();
}

OUTPUT:
enter the decimal number:10

the octal number is 12

Factorial of a number



 Factorial of a number




/*WAP to find the factorial of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,s=1;
clrscr();
printf("enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
s=s*i;
printf("%d!=%d",n,s);
getch();
}

OUTPUT:
enter the number:6

6!=720

Given number is a prime or not



Given number is a prime or not




/*WAP to check whether the given number is a prime or not*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,s=0;
clrscr();
printf("enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
s++;
}
if(s==2)
printf("%d is prime",n);
else
printf("%d is not a prime",n);
getch();
}

OUTPUT:
enter the number:19

19 is prime

Given number is a pallindrome or not


Given number is a pallindrome or not




/*WAP to check whether the given number is a pallindrome or not*/

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

OUTPUT:
enter the number:534

534 is not a pallindrome number

Generate the odd numbers between 1 to 100



Generate the odd numbers between 1 to 100




/*WAP to generate the odd numbers between 1 to 100*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("the odd numbers between 1 to 100 are:\n");
for(i=1;i<=100;i++)
{
if(i%2!=0)
printf("%d\t",i);
}
getch();
}

OUTPUT:
the odd numbers between 1 to 100 are:
1       3       5       7       9       11      13      15      17      19
21      23      25      27      29      31      33      35      37      39
41      43      45      47      49      51      53      55      57      59
61      63      65      67      69      71      73      75      77      79

81      83      85      87      89      91      93      95      97      99

Even number and odd number 1 to 20



Even number and odd number 1 to 20






/*WAP to generate the even and odd number 1 to 20*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("even number between 1 to 20 are:\n");
for(i=1;i<=20;i++)
{
if(i%2==0)
printf("%d\n",i);
}
printf("odd number between 1 to 20 are:\n");
for(i=1;i<=20;i++)
{
if(i%2!=0)
printf("%d\n",i);
}
getch();
}

OUTPUT:
even number between 1 to 20 are:
2
4
6
8
10
12
14
16
18
20
odd number between 1 to 20 are:
1
3
5
7
9
11
13
15
17

19

Fibonacci series




Fibonacci series







/*WAP to generate the fibonacci series*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,n;
a=1,b=2;
clrscr();
printf("enter the value of n:");
scanf("%d",&n);
printf("%d %d ",a,b);
while(n>2)
{
c=a+b;
printf("%d ",c);
a=b;
b=c;
n--;
}
getch();
}

OUTPUT:
enter the value of n:5

1 2 3 5 8

Tuesday, 28 October 2014

Find the real root of a quadratic equation


Find the real root of a quadratic equation




/*WAP to find the real root of a quadratic equation*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
printf("enter the value of a,b and c:");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
printf("UNREAL ROOT");
else if(d==0)
{
r1=r2=-b/2*a;
printf("real roots are %.2f and %.2f",r1,r2);
}
else
{
r1=(-b+sqrt(d))/2*a;
r2=(-b-sqrt(d))/2*a;
printf("real roots are %.2f and %.2f",r1,r2);
}
getch();
}

OUTPUT:
enter the value of a,b and c:1 4 3
real roots are -1.00 and -3.00


Change the letter if it is in lower case to upper and vice-versa



Change the letter if it is in lower case to upper and vice-versa





/*WAP to change the letter if it is in lower case to upper and vice-versa*/

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("enter the letter:");
scanf("%c",&ch);
if(ch>=65 && ch<=92)
{
ch=ch+32;
printf("letter is in upper case and its lower case is %c",ch);
}
else if(ch>=96 && ch<=122)
{
ch=ch-32;
printf("letter is in lower case and its upper case is %c",ch);
}
else
printf("INVALID LETTER");
getch();
}

OUTPUT:
enter the letter:g

letter is in lower case and its upper case is G

Check whether a year is a leap year or not



Check whether a year is a leap year or not





/*WAP to check whether a year is a leap year or not*/


#include<stdio.h>
#include<conio.h>
void main()
{
int yr;
clrscr();
printf("enter the year:");
scanf("%d",&yr);
if(yr%400==0||(yr%4==0  && yr%100!=0))
printf("%d is a leap year",yr);
else
printf("%d is not a leap year",yr);
getch();
}

OUTPUT:
enter the year:2000
2000 is a leap year


Enter marks in 5 subjects and print the divison



Enter marks in 5 subjects and print the divison





/*WAP to enter marks in 5 subjects and print the divison*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,n3,n4,n5;
float total,avg;
clrscr();
printf("enter 5 marks:");
scanf("%d%d%d%d%d",&n1,&n2,&n3,&n4,&n5);
total=n1+n2+n3+n4+n5;
avg=total/5;
if(avg>=60)
printf("FIRST CLASS");
else if(avg>=50)
printf("SECOND CLASS");
else if(avg>=30)
printf("THIRD CLASS");
else
printf("FAIL");
getch();
}

OUTPUT:
enter 5 marks:88 77 66 56 78

FIRST CLASS

Input a character and check it whether it is vowel or not using switch case



Input a character and check it whether it is vowel or not using switch case




/*WAP to input a character and check it whether it is vowel or not using switch case*/

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("enter the character:");
scanf("%c",&ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is vowel",ch);
break;
default:
printf("%c is not a vowel",ch);
}
getch();
}

OUTPUT:
enter the character:r

r is not a vowel

Check vowels using if....else statement


Check vowels using if....else statement






/*WAP to check vowels using if....else statement*/

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("enter the character:");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'                    ||ch=='O'||ch =='U')
printf("%c is vowel",ch);
else
printf("%c is not a vowel",ch);
getch();
}

OUTPUT:
enter the character:r
r is not a vowel


Accept two number from the user and display their sum



Accept two number from the user and display their sum



/*WAP to accept two number from the user and display their sum*/

#include<iostream.h>
#include<conio.h>
void main()
{
      clrscr();
      int a,b,s;
      cout<<"Enter two numbers:";
      cin>>a>>b;
      s=a+b;
      cout<<"Sum is "<<s;
      getch();
}

OUTPUT:
Enter two numbers:45 55

Sum is 100

Find the largest of three numbers


Find the largest of three numbers



/*WAP to find the largest of three numbers*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
printf("%d is gretest among them",a);
else if(b>c && b>a)
printf("%d is gretest among them",b);
else
printf("%d is gretest among them",c);
getch();
}

OUTPUT:
enter three numbers:333 656 767
767 is gretest among them


Finding area of triangle given its three side


Finding area of triangle given its three side



/*WAP to find the area of a triangle given its three side*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()                                                                 
{
float p,q,r,a,s;
clrscr();
printf("enter the three sides:");
scanf("%f%f%f",&p,&q,&r);
s=(p+q+r)/2.0;
a=sqrt(s*(s-p)*(s-q)*(s-r));
printf("area of the triangle is %.2f",a);
getch();
}

OUTPUT:
enter the three sides:3 4 5

area of the triangle is 6.00