Friday, 11 July 2014

Program for Full Pyramid in C

Create Full Pyramid in C. Input can be taken by user.

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

   for (i = 1; i <= n; i++)
   {
 for (j = 0; j < (n - i); j++)
printf("   ");
 for (j = 1; j <= i; j++)
printf(" * ");
 for (k = 1; k < i; k++)
printf(" * ");
 printf("\n");
   }

   for (i = n - 1;i >= 1; i--)
   {
 for (j = 0;j < (n - i); j++)
      printf("   ");
 for (j = 1;j <= i; j++)
printf(" * ");
 for (k = 1;k < i; k++)
      printf(" * ");
printf("\n");
   }

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

    }

Program for Full Pyramid in Java

Program for Full Pyramid and size can be input by user.

import java.util.*;
public class Pyramid
{
    public static void main(String Args[])  
    {
        int n;
        Scanner sc = new Scanner(System.in);
               n= sc.nextInt();
   for (int i = 1; i <= n; i++)
            {
                  for (int j = 0; j < (n - i); j++)
                        System.out.print("   ");
                  for (int j = 1; j <= i; j++)
                        System.out.print(" * ");
                  for (int k = 1; k < i; k++)
                        System.out.print(" * ");
                  System.out.println();
            }

            for (int i = n - 1; i >= 1; i--)
            {
                  for (int j = 0; j < (n - i); j++)
                        System.out.print("   ");
                  for (int j = 1; j <= i; j++)
                        System.out.print(" * ");
                  for (int k = 1; k < i; k++)
                        System.out.print(" * ");
                  System.out.println();
            }

            System.out.println();
     
    }
 
}

Thursday, 10 July 2014

Program for Right Triangle in Java

This is the program for Triangle and on place of "*" you can use any other variable as you want to print.

public class Triangle
{
    public static void main(String Args[])  
    {
    int i,j;
    for(i=0;i<10;i++)
 
    {
        System.out.println(" * ");
        for (j=0;j<=i;j++)
        {
            System.out.print(" * ");
       }}

    }
}

Wednesday, 9 July 2014

Program to find Grade in C Language

#include<stdio.h>
#include<conio.h>
void main()
{
float per;
clrscr();
printf("enter your percentage");
scanf("%f",&per);
if(per>=60)
printf("\n1st division");
else if(per>=45)
printf("\n2nd division");
else if(per>=33)
printf("fail");
getch();
}

Program for Switch case with two cases

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
i=2;
switch(i)
{
case 1:
{
printf("case 1");
}
case 2:
{
printf("case 2");
break;
}
default:
{
printf("default");
}
getch();
}
}

Program to print Hello in C

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("hello");
getch ();
}

Addition of two Numbers

#include<stdio.h>
#include<conio.h>
void main()
int a,b,c;
{
clrscr;
printf("\nenter the value of a");
printf("\nenter the value of b");
scanf("%d",a);
scanf("%d",b);
scanf("%d",c);
c=a+b;
getch();
}