Printing all odd number between 1&30

Monday, 29 August 2011

#include<stdio.h>
#include<conio.h>
void main()
{
int t=1;
clrscr();
while(t<30)
{
    if(t%2==1)
    printf(" %d",t);
    t++;
}
getch();
}

OUTPUT:

1  3  5  7  9  11  13  15  17  19  21  23  25  27  29





Number is Even or Odd

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter the value of a ");
scanf("%d",&a);
if(a%2==0)
 {
   printf("\nnumber is even");
 }
else
 {
   printf("\nnumber is odd");
 }
getch();
}


OUTPUT:

enter the value of a 5
number is odd




Maximum of three Number

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a");
scanf("%d",&a);
printf("\nEnter the value of b");
scanf("%d",&b);
printf("\nEnter the value of c");
scanf("%d",&c);
if(a>b&&a>c)
 {
   printf("\na is greater");
 }
if(b>a&&b>c)
 {
   printf("\nb is greater");
 }
else
 {
   printf("\nc is greater");
 }
getch();
}

OUTPUT:

Enter the value of a 5
Enter the value of b 7
Enter the value of c 9
c is greater





Maximum of three Number (nested if-else)

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a");
scanf("%d",&a);
printf("\nEnter the value of b");
scanf("%d",&b);
printf("\nEnter the value of c");
scanf("%d",&c);
if(a>b)
 {
   if(a>c)
   {
   printf("\na is greater");
   }
   else
   {
   printf("\nc is greater");
   }
}
else
{
   if(b>c)
   {
   printf("\nb is greater");
   }
   else
   {
   printf("\nc is greater");
   }
}
getch();
}

OUTPUT:

Enter the value of a 5
Enter the value of b 8
Enter the value of c 3
b is greater




Maximum of two Number

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter the value of a ");
scanf("%d",&a);
printf("\nenter the value of b ");
scanf("%d",&b);
if(a>b)
  {
    printf("\na is greater");
  }
else
  {
    printf("\nb is greater");
  }
getch();
}

OUTPUT:

enter the value of a 5
enter the value of b 4
a is greater



simple if-else program

#include<stdio.h>
#include<conio.h>
void main()
{
int a=5;
clrscr();
if(a==5)
  {
    printf("the value is 5");
  }
  else
  {
    printf(" the number is not 5");
  }
getch();
}

OUTPUT:

the value is 5





Simple if program

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

void main()
{
int a=5;
clrscr();

if(a==5)
  {
    printf(" the value of a is 5");
  }

getch();
}


OUTPUT:

the value of a is 5



Printing number 1 to10

#include<stdio.h>
#include<conio.h>
void main()
{
    int t=1;
    clrscr();
    while(t<=10)
    {
    printf("t=%d\n",t);
    t++;
    }
getch();
}

OUTPUT:

t=1
t=2
t=3
t=4
t=5
t=6
t=7
t=8
t=9
t=10





For Loop Design 5

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


OUTPUT:

5
44
333
2222
11111



For Loop Design 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:

*
**
***
****
*****





For Loop Design 3

#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("%d",j);
      }
      printf("\n");
  }
getch();
}



OUTPUT:


1
12
123
1234
12345






For Loop Design 2

#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("%d",i);
      }
      printf("\n");
  }
getch();
}


OUTPUT:

1
22
333
4444
55555






For Loop Design 1

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

getch();
}

OUTPUT:


00 01 02 03 04
10 11 12 13 14
20 21 22 23 24


TO CHECK GIVEN CHARACTER IS VOWEL OR NOT USING SWITCH CASE

#include<stdio.h>
#include<conio.h>
void main()
{
   char ch;
   clrscr();
   printf("Enter any character\n");
   scanf("%c",&ch);
   switch(ch)
     {
       case 'a':
       case 'e':
       case 'i':
       case 'o':
       case 'u':
        printf("It's Vowel\n");
          break;
       
       default:
        printf("Not a Vowel\n");
          break;
     }
getch();
}


OUTPUT:

Enter any character
e
It's Vowel






Leap Year

#include<stdio.h>
#include<conio.h>
void main()
{
int year,t1,t2;
clrscr();

printf("enter any year\n");
scanf("%d",&year);

t1=(year%100==0)&&(year%400==0);
t2=(year%100!=0)&&(year%4==0);

if(t1||t2)
  {
  printf("leap year\n");
  }
else
  {
  printf("not a leap year");
  }

getch();
}


OUTPUT:

enter any year
2004
leap yea
r



Case Conversion

#include<stdio.h>
#include<conio.h>
void main()
{
char c;
clrscr();
printf("Enter a Charactor ");
scanf("%c",&c);
if(c>=65&&c<=90)
    {
    printf("Lower case equivalent is %c\n",c+32);
    }
 else
   {
    if(c>=97&&c<=122)
      {
      printf("Upper case equivalent is %c\n",c-32);
      }
    else
      {
      printf("NOt a Charactor");
      }
   }
getch();
}


OUTPUT:


Enter a character d
Upper case equivalent is D




Backspace


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Using Backspace\b");
getch();
}


OUTPUT:

Using Backspace
/*Check the position of cursor*/


Using Backspace

Write in inverted comma


#include<stdio.h>
#include<conio.h>void main()
{
clrscr();
printf("\"Hey! i m learning C \"");
getch();
}


OUTPUT:

"Hey! i m learning C "

Sound Magic


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


void main()
{
clrscr();
printf("This will give a beep\a");
getch();
}


OUTPUT:

This will give a beep


Carriage Return

Sunday, 28 August 2011


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("First Line\n");
printf("Second Line\r");
getch();
}


OUTPUT:

First Line
Second Line
/*Check the cursor position*/

Tab between two Words


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


OUTPUT:

First    Second

Enter in New line


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("First Line");
printf("\nSecond line");
getch();
}


OUTPUT:


First Line
Second line

Printing of ASCII value of charactor


#include<stdio.h>
#include<conio.h>
void main()
{
char a;
clrscr();
printf("Enter a charactor value\n");
scanf("%c",&a);
printf("Ascii value is %d",a);
getch();
}

OUTPUT:

Enter a character value a
Ascii value is 97

Simple Data type Program

#include<stdio.h>
#include<conio.h>
void main()
{
char ch1,ch2,ch3,ch4;
clrscr();


ch1='+';
ch2='-';
ch3='*';
ch4='/';


printf("ch1=%d\tch2=%d\tch3=%d\tch4=%d",ch1,ch2,ch3,ch4);
getch();
}


OUTPUT:

ch1=43   ch2=45   ch3=42   ch4=47


Swaping with Two Variable


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of a&b");
scanf("%d%d",&a,&b);
printf("\na=%d",a);
printf("\nb=%d",b);


a=a+b;
b=a-b;
a=a-b;


printf("the value after swaping");
printf("\na=%d",a);
printf("\nb=%d",b);
getch();
}


OUTPUT:

Enter the value of a&b4
5
a=4
b=5
the value after swaping
a=5
b=4

Swaping with Three Variable


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a&b");
scanf("%d%d",&a,&b);
printf("\na=%d",a);
printf("\nb=%d",b);


c=a;
a=b;
b=c;


printf("the value after swaping");
printf("\na=%d",a);
printf("\nb=%d",b);
getch();
}


OUTPUT:



Enter the value of a&b4
5
a=4
b=5
the value after swaping
a=5
b=4 

Average of Two Number


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the value of a&b");
scanf("%d%d",&a,&b);


c=(a+b)/2.0;


printf("the value of c is %d",c);
getch();
}

OUTPUT:
enter the value of a&b 4
5
the value of c is 4.5


Area OF Square


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


void main()
{
int s,a;
clrscr();
printf("Enter one side of square");
scanf("%d",&s);
a=s*s;
printf("\nThe area of square is %d sq.units",a);
getch();
}


OUTPUT:
Enter one side of square 5
The area of square is 25 sq. units

Addtion of Two Variable in C


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

void main()

{

int a,b,c;
clrscr();

printf("enter the value of a&b");
scanf("%d%d",&a,&b);

c=a+b;

printf("\nthe value of c is %d",c);

getch();

}




OUTPUT:


enter the value of a&b
4
5
the value of c is 9

Simple Hello Program in C



#include<stdio.h>

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


OUTPUT:


Hello

 

Blogger news

Blogroll

Enter your email address:

Delivered by FeedBurner

Total Pageviews

Followers

Most Reading