Friday, May 11, 2012
Program to check that entered no is divisible by 5 or not.
//program to check that entered no is divisible by 5 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s,i;
printf("Enter the no ");
scanf("%d",&n);
s=0;
for(i=0;i<1;i++)
{ r=n%10;
n=n/10;
}
if(r==0||r==5)
printf("Entered no is divisible by 5");
else
printf("Entered no is Not divisible by 5");
getch();
}
Program to count number of digits in a number.
// program to count number of digits in a number.
#include<stdio.h>
#include<conio.h>
main()
{
int num,count=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num)
{
num=num/10;
count++;
}
printf("Total digits is: %d",count);
getch();
}
Program to check that entered no is divisible by 9 or not.
//program to check that entered no is divisible by 9 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s;
printf("Enter the no ");
scanf("%d",&n);
s=0;
while(r!=0)
{ r=n%10;
n=n/10;
s=s+r;
}
if(s%9==0)
printf("Entered no is divisible by 9");
else
printf("Entered no is Not divisible by 9");
getch();
}
Program to check that entered no is divisible by 10 or not.
//program to check that entered no is divisible by 10 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s,i;
printf("Enter the no ");
scanf("%d",&n);
s=0;
for(i=0;i<1;i++)
{ r=n%10;
n=n/10;
}
if(r==0)
printf("Entered no is divisible by 10");
else
printf("Entered no is Not divisible by 10");
getch();
}
Thursday, May 3, 2012
Program to check that entered no is divisible by 3 or not.
//program to check that entered no is divisible by 3 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s;
printf("Enter the no ");
scanf("%d",&n);
s=0;
while(r!=0)
{ r=n%10;
n=n/10;
s=s+r;
}
if(s%3==0)
printf("Entered no is divisible by 3");
else
printf("Not divisible by 3");
getch();
}
Sunday, March 18, 2012
Program To print the two dimensional array.
//To print the two dimensional array.
#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3],i,j;
printf("Enter the value of 3X3 array:-");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{ scanf("%d",&a[i][j]);
}
}
printf("The 2D array is :");
for(i=0;i<3;i++)
{ printf("\n\n");
for(j=0;j<3;j++)
{ printf("%d ",a[i][j]);
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3],i,j;
printf("Enter the value of 3X3 array:-");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{ scanf("%d",&a[i][j]);
}
}
printf("The 2D array is :");
for(i=0;i<3;i++)
{ printf("\n\n");
for(j=0;j<3;j++)
{ printf("%d ",a[i][j]);
}
}
getch();
}
Labels:
Array
To print the reverse of character.
//To print the reverse of character.
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char a[5];
printf("Enter the name- ");
for(i=0;i<5;i++)
scanf("%c",&a[i]);
printf("Your name is: ");
for(i=0;i<5;i++)
printf("%c",a[i]);
printf("\nYour reverse name is: ");
for(i=4;i>=0;i--)
printf("%c",a[i]);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char a[5];
printf("Enter the name- ");
for(i=0;i<5;i++)
scanf("%c",&a[i]);
printf("Your name is: ");
for(i=0;i<5;i++)
printf("%c",a[i]);
printf("\nYour reverse name is: ");
for(i=4;i>=0;i--)
printf("%c",a[i]);
getch();
}
Labels:
Array
Program To take character from the user by array .
//To take character from the user by array .
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char a[5];
printf("Enter the name ");
for(i=0;i<=4;i++)
scanf("%c",&a[i]);
printf("Your name is ");
for(i=0;i<=4;i++)
printf("%c",a[i]);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char a[5];
printf("Enter the name ");
for(i=0;i<=4;i++)
scanf("%c",&a[i]);
printf("Your name is ");
for(i=0;i<=4;i++)
printf("%c",a[i]);
getch();
}
Labels:
Array
Saturday, March 17, 2012
Program for identify +ve and -ve no in an array .
Program for identify +ve and -ve no in an array .
#include<stdio.h>
#include<conio.h>
main()
{
int n[15],m,e,i;
m=n[0];
printf("Enter the 10 no ");
for(i=0;i<10;i++)
{
scanf("%d",&n[i]);
}
printf("\nThe positive no are:\n");
for(i=0;i<10;i++)
{
if(n[i]>0)
{
printf("%d,",n[i]);
}
}
printf("\nThe negative no are:\n");
for(i=0;i<10;i++)
{
if(n[i]<0)
{
printf("%d,",n[i]);
}
}
getch();
}
Labels:
Array
Program to find odd and even nos. in an array.
//Program to find odd and even nos. in an array.
#include<stdio.h>
#include<conio.h>
main()
{
int n[10],i;
printf("Enter the 10 no ");
for(i=0;i<10;i++)
{
scanf("%d",&n[i]);
}
printf("The even nos: ");
for(i=0;i<10;i++)
{
if(n[i]%2==0)
{
printf("%d,",n[i]);
}
}
printf("\nThe odd nos : ");
for(i=0;i<10;i++)
{
if(n[i]%2!=0)
{ //o[i]=n[i];
printf("%d,",n[i]);
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int n[10],i;
printf("Enter the 10 no ");
for(i=0;i<10;i++)
{
scanf("%d",&n[i]);
}
printf("The even nos: ");
for(i=0;i<10;i++)
{
if(n[i]%2==0)
{
printf("%d,",n[i]);
}
}
printf("\nThe odd nos : ");
for(i=0;i<10;i++)
{
if(n[i]%2!=0)
{ //o[i]=n[i];
printf("%d,",n[i]);
}
}
getch();
}
Labels:
Array
Program for finding Largest no.
//Program for finding Largest no.
#include<stdio.h>
#include<conio.h>
main()
{
int n[15],m,i;
printf("Enter the 10 no ");
for(i=0;i<10;i++)
{
scanf("%d",&n[i]);
}
printf("The entered array is ");
for(i=0;i<10;i++)
{printf(" ");
printf("%d",n[i]);
}
m=n[0];
for(i=0;i<10;i++)
{
if(n[i]>m)
{
m=n[i];
}
}
printf("\nLargest is %d",m);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int n[15],m,i;
printf("Enter the 10 no ");
for(i=0;i<10;i++)
{
scanf("%d",&n[i]);
}
printf("The entered array is ");
for(i=0;i<10;i++)
{printf(" ");
printf("%d",n[i]);
}
m=n[0];
for(i=0;i<10;i++)
{
if(n[i]>m)
{
m=n[i];
}
}
printf("\nLargest is %d",m);
getch();
}
Labels:
Array
Program for addition of 10 no's.
//Addition of 10 no's.
#include<stdio.h>
#include<conio.h>
main()
{
int n[15],o=0,e,i;
printf("Enter the 10 no ");
for(i=0;i<5;i++)
{
scanf("%d",&n[i]);
}
printf("The entered array is ");
for(i=0;i<5;i++)
{printf(" ");
printf("%d",n[i]);
}
for(i=0;i<5;i++)
{
o=o+n[i];
}
printf("Sum =%d",o);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int n[15],o=0,e,i;
printf("Enter the 10 no ");
for(i=0;i<5;i++)
{
scanf("%d",&n[i]);
}
printf("The entered array is ");
for(i=0;i<5;i++)
{printf(" ");
printf("%d",n[i]);
}
for(i=0;i<5;i++)
{
o=o+n[i];
}
printf("Sum =%d",o);
getch();
}
Labels:
Array
Program to Print fibonacci series.
// The fibonacci series.
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,f,s,t;
printf("How many element you want to print:");
scanf("%d",&n);
f=0;
s=1;
printf("The fibonacci series up to %d is : %d,%d",n,f,s);
for(i=0;i<n-2;i++)
{
t=f+s;
f=s;
s=t;
printf(",%d",t);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,f,s,t;
printf("How many element you want to print:");
scanf("%d",&n);
f=0;
s=1;
printf("The fibonacci series up to %d is : %d,%d",n,f,s);
for(i=0;i<n-2;i++)
{
t=f+s;
f=s;
s=t;
printf(",%d",t);
}
getch();
}
Saturday, March 10, 2012
Program to print the pyramid of no.
//Program to print the pyramid of no.
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i,g;
y=1;
for(x=3;x>=0;x--)
{
for(i=1;i<=x;i++)
{printf(" ");
}g=1;
for(i=0;i<y;i++)
{printf(" %d",g);g++;
}
y=y+2;
printf("\n\n");
}
getch();
}
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i,g;
y=1;
for(x=3;x>=0;x--)
{
for(i=1;i<=x;i++)
{printf(" ");
}g=1;
for(i=0;i<y;i++)
{printf(" %d",g);g++;
}
y=y+2;
printf("\n\n");
}
getch();
}
Program to Print the pyramid.
//Program to Print the pyramid.
*
***
*****
*******
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i;
y=1;
for(x=3;x>=0;x--)
{
for(i=1;i<=x;i++)
{printf(" ");
}
for(i=0;i<y;i++)
{printf("*");
}
y=y+2;
printf("\n\n");
}
getch();
}
*
***
*****
*******
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i;
y=1;
for(x=3;x>=0;x--)
{
for(i=1;i<=x;i++)
{printf(" ");
}
for(i=0;i<y;i++)
{printf("*");
}
y=y+2;
printf("\n\n");
}
getch();
}
Program to Print the pyramid.
//Program to Print the pyramid.
*
***
*****
*******
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i;
y=1;
for(x=3;x>=0;x--)
{
for(i=1;i<=x;i++)
{printf(" ");
}
for(i=1;i<=y;i++)
{printf("*");
}
y=y+2;
printf("\n");
}
getch();
}
*
***
*****
*******
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i;
y=1;
for(x=3;x>=0;x--)
{
for(i=1;i<=x;i++)
{printf(" ");
}
for(i=1;i<=y;i++)
{printf("*");
}
y=y+2;
printf("\n");
}
getch();
}
Program to print the reverse pyramid of no.
//Program to print the reverse pyramid of no.
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7
1 2 3 4 5
1 2 3
1
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i,g;
y=9;
for(x=4;x>=0;x--)
{
for(i=4;i>x;i--)
{printf(" ");
}g=1;
for(i=0;i<y;i++)
{printf("%d",g);g++;
}
y=y-2;
printf("\n");
}
getch();
}
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7
1 2 3 4 5
1 2 3
1
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i,g;
y=9;
for(x=4;x>=0;x--)
{
for(i=4;i>x;i--)
{printf(" ");
}g=1;
for(i=0;i<y;i++)
{printf("%d",g);g++;
}
y=y-2;
printf("\n");
}
getch();
}
Program to Print the pyramid.
//Print the pyramid like..
*********
*******
*****
***
*
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i;
y=9;
for(x=4;x>=0;x--)
{
for(i=4;i>x;i--)
{printf(" ");
}
for(i=0;i<y;i++)
{printf("*");
}
y=y-2;
printf("\n");
}
getch();
}
*********
*******
*****
***
*
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,i;
y=9;
for(x=4;x>=0;x--)
{
for(i=4;i>x;i--)
{printf(" ");
}
for(i=0;i<y;i++)
{printf("*");
}
y=y-2;
printf("\n");
}
getch();
}
Program to check entered character is special symbol or not.
//Program to check entered character is special symbol or not.
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char c;
printf("Enter character");
scanf("%c",&c);
i=c;
if((c>=0&&c<=47)||(c>=58&&c<=64))
printf("You entered a special character ");
else
printf("Not special character");
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char c;
printf("Enter character");
scanf("%c",&c);
i=c;
if((c>=0&&c<=47)||(c>=58&&c<=64))
printf("You entered a special character ");
else
printf("Not special character");
getch();
}
Program to check entered character is capital or small.
//Program to check entered character is capital or small.
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char a;
printf("Enter a character capital or small-");
scanf("%c",&a);
i=a;
if(i>=65&&i<=90)
{printf("you entered capital letter");}
if(i>=97&&i<=122)
printf("You entered small letter");
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char a;
printf("Enter a character capital or small-");
scanf("%c",&a);
i=a;
if(i>=65&&i<=90)
{printf("you entered capital letter");}
if(i>=97&&i<=122)
printf("You entered small letter");
getch();
}
Friday, March 9, 2012
Program to Interchange the value.
//Program to Interchange the value.
#include<stdio.h>
#include<conio.h>
main()
{ int a,b,temp;
printf("Enter the value of a and b -");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("The changed value of a and b -%d & %d",a,b);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int a,b,temp;
printf("Enter the value of a and b -");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("The changed value of a and b -%d & %d",a,b);
getch();
}
Labels:
c basic program
Program to print negative no.
//Program to print negative no.
#include<stdio.h>
#include<conio.h>
main()
{
int i,n;
printf("Enter any no ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d\n",-i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,n;
printf("Enter any no ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d\n",-i);
}
getch();
}
Labels:
c basic program
Program to print the triangle of no.
// Program to calculate the triangle of no.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
#include<conio.h>
main()
{
int x,i;
for(x=1;x<=5;x++)
{
for(i=1;i<=x;i++)
{
printf(" %d",i);
}
printf("\n\n");
}
getch();
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
#include<conio.h>
main()
{
int x,i;
for(x=1;x<=5;x++)
{
for(i=1;i<=x;i++)
{
printf(" %d",i);
}
printf("\n\n");
}
getch();
}
Program to Print the triangle of star.
// Program to calculate the triangle of star.
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
main()
{
int x,i;
for(x=1;x<=5;x++)
{
for(i=1;i<=x;i++)
{
printf(" *");
}
printf("\n\n");
}
getch();
}
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
main()
{
int x,i;
for(x=1;x<=5;x++)
{
for(i=1;i<=x;i++)
{
printf(" *");
}
printf("\n\n");
}
getch();
}
Thursday, March 8, 2012
Entered no is Armstrong no or not.
//Entered no is Armstrong no or not.
#include<stdio.h>
#include<conio.h>
main()
{ int d,r,n,s;
printf("Enter no:");
scanf("%d",&n);
d=n;
s=0;
do
{
r=d%10;
d=d/10;
s=s+(r*r*r);
}while(d!=0);
if(s==n)
printf("Armstrong no");
else
printf("Not Armstrong no");
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int d,r,n,s;
printf("Enter no:");
scanf("%d",&n);
d=n;
s=0;
do
{
r=d%10;
d=d/10;
s=s+(r*r*r);
}while(d!=0);
if(s==n)
printf("Armstrong no");
else
printf("Not Armstrong no");
getch();
}
Program to reverse the entered no .
//Program to reverse the entered no .
#include<stdio.h>
#include<conio.h>
main()
{ int d,r,n;
printf("Enter no:");
scanf("%d",&n);
d=n;
do
{
r=d%10;
printf("%d",r);
d=d/10;
}while(d!=0);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int d,r,n;
printf("Enter no:");
scanf("%d",&n);
d=n;
do
{
r=d%10;
printf("%d",r);
d=d/10;
}while(d!=0);
getch();
}
Program to find factorial of any no.
//Program to find factorial of any no.
#include<stdio.h>
#include<conio.h>
main()
{
int i,fact,n;
printf("Enter the no:");
scanf("%d",&n);
fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("The factorial of %d no is :- %d",n,fact);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,fact,n;
printf("Enter the no:");
scanf("%d",&n);
fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("The factorial of %d no is :- %d",n,fact);
getch();
}
Program to print first n natural no and their sum
//Program to print first n natural no and their sum.
#include<stdio.h>
#include<conio.h>
main()
{
int i,sum,n;
printf("How many natural no?");
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++)
{ printf("%d\n",i);
sum=sum+i;
}
printf("The sum of first %d natural no is :-%d",i,sum);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,sum,n;
printf("How many natural no?");
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++)
{ printf("%d\n",i);
sum=sum+i;
}
printf("The sum of first %d natural no is :-%d",i,sum);
getch();
}
Show all odd numbers from 0 to your entered no.
//Show all odd numbers from o to your entered no.
#include<stdio.h>
#include<conio.h>
main()
{ int i,n;
printf("Enter any no-");
scanf("%d",&n);
printf("Odd no is-");
for(i=1;i<=n;i=i+2)
{
printf("%d\n",i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int i,n;
printf("Enter any no-");
scanf("%d",&n);
printf("Odd no is-");
for(i=1;i<=n;i=i+2)
{
printf("%d\n",i);
}
getch();
}
Count backwards of any no.
//Count backwards of any no using a for loop.
#include<stdio.h>
#include<conio.h>
main()
{ int i,n;
printf("Enter any no-");
scanf("%d",&n);
printf("backwards of no--");
for(i=n;i>=0;i--)
{ printf("%d\n",i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{ int i,n;
printf("Enter any no-");
scanf("%d",&n);
printf("backwards of no--");
for(i=n;i>=0;i--)
{ printf("%d\n",i);
}
getch();
}
Program to Print Table of any no
//table of any no
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,m;
printf("Enter any no-");
scanf("%d",&n);
for(i=1;i<=10;i++)
{ m=n*i;
printf("%d",m);
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,m;
printf("Enter any no-");
scanf("%d",&n);
for(i=1;i<=10;i++)
{ m=n*i;
printf("%d",m);
printf("\n");
}
getch();
}
Table of two
//table of two
#include<stdio.h>
#include<conio.h>
main()
{
int i,m;
for(i=1;i<=10;i++)
{ m=2*i;
printf("%d",m);
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,m;
for(i=1;i<=10;i++)
{ m=2*i;
printf("%d",m);
printf("\n");
}
getch();
}
Simple for loop program
//Loop Control Structure
#include<stdio.h>
#include<conio.h>
main()
{
int i;
for(i=0;i<=10;i++)
{
printf("%d",i);
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i;
for(i=0;i<=10;i++)
{
printf("%d",i);
printf("\n");
}
getch();
}
Enter any charecter and get ASCII value.
//Enter any charecter and get ASCII value.
#include<stdio.h>
#include<conio.h>
main( )
{ char a;
int n;
printf("enter the char--");
scanf("%c",&a);
printf("%d",a);
getch();
}
#include<stdio.h>
#include<conio.h>
main( )
{ char a;
int n;
printf("enter the char--");
scanf("%c",&a);
printf("%d",a);
getch();
}
Labels:
c basic program
Program to sum two no
//sum of two no
#include<stdio.h>
#include<conio.h>
main( )
{ int n,m,s;
printf("Enter two no --");
scanf("%d%d",&n,&m);
s=n+m;
printf("The sum of two no-%d ",s);
getch();
}
#include<stdio.h>
#include<conio.h>
main( )
{ int n,m,s;
printf("Enter two no --");
scanf("%d%d",&n,&m);
s=n+m;
printf("The sum of two no-%d ",s);
getch();
}
Labels:
c basic program
Wednesday, March 7, 2012
Calculation of simple interest
/* Calculation of simple interest */
#include<stdio.h>
#include<conio.h>
main( )
{
int p, n ;
float r, si ;
printf( "Enter values of p, n(year),r(rate)" ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ("%f",si);
getch();
}
#include<stdio.h>
#include<conio.h>
main( )
{
int p, n ;
float r, si ;
printf( "Enter values of p, n(year),r(rate)" ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ("%f",si);
getch();
}
Labels:
c basic program
welcome to c
// Welcome to c programming.
#include<stdio.h>
#include<conio.h>
main()
{
printf("Welcome to c programming ");
printf("\n");
printf("This is our first program");
getch();
}
This is basic c program.This program doesn't take any input from the user .
#include<stdio.h>
#include<conio.h>
main()
{
printf("Welcome to c programming ");
printf("\n");
printf("This is our first program");
getch();
}
This is basic c program.This program doesn't take any input from the user .
Labels:
c basic program
Subscribe to:
Comments (Atom)