Showing posts with label basic program. Show all posts
Showing posts with label basic program. Show all posts

Sunday, June 30, 2013

Write a program to find no of letter, space,symbol in given line?

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

void main()
{
char c,number=0,ucharacter=0,lcharacter=0,space=0,symbol=0;
clrscr();
printf("\n enter the character \n\n");
do{
c=getchar();
if(c>='a'&&c<='z')
lcharacter++;
else
if
(c>='A'&&c<='Z')
ucharacter++;
else
if
(c==' ')
space++;
else
if
(c>='0'&&c<='9')
number++;
elsesymbol++;
}
while(c!='\n');
printf("\nupper letter=%d\nlower letter=%d\nnumber=%d\nspace=%d\nsymbol=%d",ucharacter,lcharacter,number,space,(symbol-1));

getch();
}

Output:
image


{ Read More }


Saturday, June 29, 2013

Write a program to whether the given character is vowel or not?

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

void main()
{
char c;
clrscr();
printf("\n enter the character ");
scanf("%c",&c);
switch(c)
{
case'a':
case'e':
case'i':
case'o':
case'u':
printf("\n the %c  is vowel",c);
break;
default:

printf("\n the %d  is consonant",c);
}

getch();
}

output:
image


{ Read More }


Write a program to find the smallest no in given array ?

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

void main()
{
int no[100],i,n,high=
32767;//maximum possible value in signed integer
clrscr();
printf("\n enter the no of no ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&no[i]);
if(high>no[i])
high=no[i];
}

printf("\n the %d  is smaller",high);
getch();
}

Output:
image


{ Read More }


Write a program to find the greatest no in given array?

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

void main()
{
int no[100],i,n,high=0;
clrscr();
printf("\n enter the no of no ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&no[i]);
if(high<no[i])
high=no[i];
}

printf("\n the %d  is greater",high);
getch();
}

Output:
image



{ Read More }


Write a program to find the greatest of 3 no?

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

void main()
{
int no1,no2,no3;
clrscr();
printf("\n enter the  no1,no2 and no3 ");
scanf("%d%d%d",&no1,&no2,&no3);

if(no1>no2&&no1>no3)
printf("\n the %d  is greater",no1);
else
if
(no2>no3)
printf("\n the %d is greater",no2);
elseprintf("\n the %d is greater",no3);
getch();
}

Output:
image


{ Read More }


Write a program to find the greatest of 2 no?

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

void main()
{
int no1,no2;
clrscr();
printf("\n enter the  no1 and no2 ");
scanf("%d%d",&no1,&no2);

if(no1>no2)
printf("\n the %d  is greater",no1);
elseprintf("\n the %d is greater",no2);
getch();
}

Output:
image


{ Read More }


Write a program to find the given no is Armstrong or not ?

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

void main()
{
int no1,temp1,sum=0,n;
clrscr();
printf("\n enter the  no ");
scanf("%d",&no1);
temp1=no1;
while(no1!=0)
{
n=no1%10;
sum=sum+n*n*n;
n01=no1/10;
}
if(sum==temp1)
printf("\n the %d  is armstrong",temp1);
elseprintf("\n the %d not armstrong",temp1);
getch();
}

Output:
image
What is Armstrong no ?
the no is said to be armstrong if satisfy the following condition ,i.e 153=1*1*1+5*5*5+3*3*3 

{ Read More }


Write a program to find the given two no is co-prime or not ?

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

void main()
{
int no1,no2,temp,temp1,temp2;
clrscr();
printf("\n enter the two no decesending order ");
scanf("%d%d",&no1,&no2);
temp1=no1;
temp2=no2;
while(no2!=0)
{
temp=no1%no2;
no1=no2;
no2=temp;
}
if(no1==1)
printf("\n the %d and %d is co-prime",temp1,temp2);
else
printf("\n the %d and %d is not co-prime",temp1,temp2);
getch();
}

Output:
image
What is co-prime ?
The 2 no which has highest common factor as 1 is called co-prime.



{ Read More }


Write a program to find the given no is prime or not ?

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

void main()
{
int n,i,x=0;
clrscr();
printf("\nEnter the no");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
x++;
}
if(x>1)
printf("\n the %d is prime",n);
else

printf("\n the %d is not prime",n);
getch();
}

Output
image
What is prime no?
the number which is not divisible by any other no except that no  is called prime no
{ Read More }


Write a program to print the Fibonacci series ?

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

void main()
{
int n1=0,n2=1,n,sum=0;
clrscr();
printf("\nEnter the limit of the series");
scanf("%d",&n);
printf("\n%d",n1);
printf("\n%d",n2);
while(sum<n)
{
sum=n1+n2;
n1=n2;
n2=sum;
printf("\n%d",sum);
}
getch();
}

Output:
image
What is Fibonacci series ?
the series which is obtained by addition of two previous no is called Fibonacci series.
{ Read More }