counter

Free Hit Counter

C program to print a pattern

Q: 1
1 2
1 2 3
1 2 3 4
#include
#include
void main()
{
int i,j,n,k=1;
clrscr();
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d ",k);
}
printf("\t\n");

}
getch();
}

C program to print a pattern

Q: 5
4 4
3 3 3
2 2 2 2
1 1 1 1 1

#include #include void main() { int i,j=1,n,k=1; clrscr(); printf("enter value of n:"); scanf("%d",&n); for(i=n;i>=1;i--) { printf("\t\n"); for(k=1;k<=j;k++) { printf("%d",i); } j++; printf("\t\n"); } getch(); }

C program to print a pattern

Q: print 1
1 2
1 2 3
1 2 3 4


#include
#include
void main()
{
int i,j,n,k;
clrscr();
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}

for(k=1;k<=i;k++)
{
printf("%d",k);
}
printf("\n");

}
getch();
}

C program to print a pattern

Q:
!
2 3
4 5 6
7 8 9 10


#include
#include
void main()
{
int i,j,n,k=1,c=1;
clrscr();
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d ",c);
c++;
}
printf("\t\n");

}
getch();
}

C program to print a pattern

Q: 1
2 2
3 3 3
4 4 4 4


#include
#include
void main()
{
int i,j,n,k;
clrscr();
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d ",i);
}
printf("\t\n");

}
getch();
}

C program to print a pattern

Q:
1
22
333
4444
55555


#include
#include
void main()
{
int i,j,n,k;
clrscr();
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
printf("\t\n");
for(k=1;k<=i;k++)
{
printf("%d",i);
}
printf("\t\n");

}
getch();
}

C program to print a pattern

Q:Print 1
22
333
4444
55555


#include
#include
void main()
{
int i,j,n;
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}

C program to print a pattern

Q: Print 1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5


#include
#include
void main()
{
int i,j,n;
printf("enter value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}

C program to convert decimal into octal numbers

Q: program to find octal equivalent

#include
#include
#include
void main()
{
int no;
clrscr();
printf("enter any no: ");
scanf("%d",&no);
printf("octal=%o",no);
getch();
}

C program to print armstrong numbers


Q:A program to print Armstrong numbers between 1 to 500

#include
#include
#include
void main ()
{
int i=1,a,b,c;
clrscr();
while(i<=500)
{

a=i%10;
b=i%100;
b=(b-a)/10;
c=i/100;
if(a*a*a+b*b*b+c*c*c==i)
{
printf("armstrong no.:%d\n",i);
}
i++;
}
getch();
}

C program to print ascii values

Q:program to print all the ascii values and their equivalent characters using a while loop


#include
#include
#include
void main ()
{
int i=0;
clrscr();
while(i<=255)
{
printf("%d:%c\t",i,i);
i++;
}

getch();

}

C program to find power

Q: program to find the power of any number without using the function power


#include
#include
void main()
{
int no1,no2,i=1;
long int power=1;
printf("enter two nombers :);
scanf("%d",&no1);
scanf("\n%d",&no2);
while(no2>i)
{
power=power*x;
i++;
}
printf("%d",power);
getch();
}




C program to find power of any number

Q: To find the value of one number raised to another number using the power function.

#include
#include
#include
void main ()
{
int a,b,c;
printf("enter first no.");
scanf("%d",&a);
printf("enter second no.");
scanf("%d",&b);
c=pow(a,b);
printf("%d",c);
getch();
}

C program to find factorial

Q: program to find the factorial value of any number entered through the keyboard.


#include
#include
void main()
{
int i=1,num,fact=1;
clrscr();
printf("enter any number: ");
scanf("%d",&num);
while(i<=num)
{
fact=fact*i;
i++;
}
printf("\tfactorial=%d",fact);
getch();
}

C program to print result of a series

Q: program to print total of 1-2+3-4+5-6+7....


#include
#include
void main()
{
int k,sum=0;
clrscr();
for(k=1;k<=10;k++)
{
if(k%2==1)
sum=sum+k;
else
sum=sum-k;
}
printf("sum=%d ",sum);
getch();
}

C program to print a series

Q: program to print total of (1/2)+(2/3)+....+(9/10)


#include
#include
void main()
{
float i=1,k,j=2,sum=0;
clrscr();
for(k=1;k<=9;k++)
{
sum=sum+(i/j);
i++;
j++;
}
printf("sum=%f ",sum);
getch();
}

C program to print sum of first 50 natural numbers

Q:program to print total of 1 to 50

#include
#include
void main()
{
int i,sum=0;
clrscr();


for(i=0;i<=50;i++)
{
sum=sum+i;
}
printf("sum=%d ",sum);
getch();
}

C program to print even numbers between 0 to 200

Q: program to print first 100 even numbers


#include
#include
void main()
{
int i;
clrscr();


for(i=0;i<=200;i++)
{
if(i%2==0)
printf("%d ",i);
}
getch();
}

C program to print series

Q: program to print 1,11,20,28,35,41,46,50,...........


#include
#include
void main()
{
int i=10,sum=1;
clrscr();
printf("%d ",sum);

for(i=10;i>=1;i--)
{
sum=sum+i;
printf("%d ",sum);
}
getch();
}

C program to print a series

Q: program to print 1,10,2,9,3,8,4,7,5,6.....


#include
#include
void main()
{
int i=1,c,j=10;
clrscr();

for(c=1;c<=10;c++)
{
if(c%2==1)
{
printf("%d ",i);
i++;
}
else
{
printf("%d ",j);
j--;
}
}
getch();
}

C program to print ten natural numbers in reverse

Q:program to print 10 to 1


#include
#include
void main()
{
int i;
clrscr();
for(i=10;i>=1;i--)
{
printf("%d\n",i);
}
getch();
}

C program to print the squares of natural numbers

Q: program to print 1,2,4,6,16,....


#include
#include
void main()
{
int i=1,p=1;
clrscr();
printf("%d\n",i);
while(p<64)
{
p=(p*2);
printf("%d\n",p);
}
getch();

}

C program to print even numbers

\\program to print 2,4,6,8....

#include
#include
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
if(i%2==0)
printf("\t%d\n",i);
}
getch();
}

C program to print ten natural numbers

\\program to print 1 to 10

#include
#include
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}
getch();
}

Counting of array elements

Q: nos are entered thru the keyboard and the no. of positive,negative and zero elements also the count of odd and even nos present in the array are displayed


#include
#include
void main()
{
int a[25],i,z=0,p=0,n=0,o=0,e=0;
clrscr();
for(i=0;i<5;i++)
{
printf("enter any no.:");
scanf("%d",&a[i]);
}

for(i=0;i<5;i++)
{

if(a[i]==0)
z++;
else if(a[i]>0)
p++;
else
n++;
}
for(i=0;i<5;i++)
{
if(a[i]%2==0)
e++;
else
o++;
}
printf("no of Zero elements:%d\n",z);
printf("no of positive nos:%d\n",p);
printf("no of negative nos:%d\n",n);
printf("no of odd nos:%d\n",o);
printf("no of even nos:%d\n",e);

getch();
}



Search no. in array

Q: nos are entered thru the keyboard and the no. searched by the user is displayed if it is present in the array


#include
#include
void main()
{
int a[25],i,n,c=0;
clrscr();
for(i=0;i<5;i++)
{
printf("enter any no.:");
scanf("%d",&a[i]);
}
printf("Enter the no. to be searched:");
scanf("%d",&n);
for(i=0;i<=5;i++)
{

if(n==a[i])
c++;
}
if(c>0)
{
printf("%d\n",n);
printf("the no is present %d times",c);
}
else
printf("no. not present in array");
getch();
}



C program to check if input year is leap year

Q:C program to check if input year is leap year or not when the year is input from the user

#include
#include
void main()
{
int year;
clrscr();
printf("enter any year: ");
scanf("%d",year);
if(year%400==0 || year%100!=0 && year%4==0)
{
printf("this year is leap year");
}
else
{
printf("this year is not leap year");
}
getch();
}

c program to check position of point in a circle


Q:Write a c program to check whether a given point is outside, inside or on the circle when radius and coordinates of points are input



#include
#include
void main()
{
int x,y,r,d;
clrscr();
printf("enter x co ordinate");
scanf("%d",&x);
printf("enter y co ordinate");
scanf("%d",&y);
printf("enter radius");
scanf("%d",&r);

d=(x*x)+(y*y);
r=r*r;
if(d==r)
{
printf("point is on the circle");
}
else if(d>r)
{
printf("point is outside the circle");
}
else if(d
{
printf("point is inside the circle");
}
getch();
}

C program to check if points are collinear


Q:Given three points,write a program to check whether the given points fall in a straight line


#include
#include
void main()
{
int x1,x2,y1,y2,x3,y3;
int s1,s2,s3;
clrscr();
printf("enter value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter value of x2,y2:");
scanf("%d%d",&x2,&y2);
printf("enter value of x3,y3:");
scanf("%d%d",&x3,&y3);
s1=abs(x2-x1)/abs(y2-y1);
s2=abs(x3-x1)/abs(y3-y1);
s3=abs(x3-x2)/abs(y3-y2);
if(s1==s2&&s1==s3)
{
printf("points are collinear");
}
else
{
printf("points are not collonear");
}
getch();
}



C program to compare area and perimeter


Q:Given the length and breadth of rectangular,write a program to find whether the area of the rectangle is greater than its perimeter.

#include
#include
void main()
{
int l,b,a,p;
clrscr();
printf("enter the length: ");
scanf("%d",&l);
printf("enter the bragth: ");
scanf("%d",&b);
a=l*b;
p=2*l+2*b;
if(a>p)
{
printf("area is big");
}
else
{
printf("perameter is big");
}
getch();
}

C program to check validity of triangle


Q:Write a c program to check whether a triangle is valid or not ..when the three angles of the triangle are entered through keyboard.A triangle is valid if sum of all angles is 180

#include
#include
void main()
{
int A1,A2,A3;
clrscr();
printf("enter three angles: ");
scanr("%d",&A1);
scanf("\n%d",&A2);
scanf("\n%d",&A3);
if(A1+A2+A3==180)
{
printf("valid tringle");
}
else
{
printf("invalid tringle");
}
getch();
}

C program to show age comparision


Q: IF the ages of ram, shyam and Ajay are input through the keyboard,write a program to determine the youngest of three

#include
#include
void main()
{
int Ar,As,Aa;
printf("enter the age of ram,shyam,ajay");
scanf("%d%d%d",&Ar,&As,&Aa);
if(Ar
{
printf("ram is youngest");
}
elseif(As
{
printf("shyam is youngest");
}
else
{
printf("ajay is youngest");
}
getch();
}

C program to display day on !st january of any year



Q:According to Gregorian calendar,it was monday on 01/01/1900.If any year is input through the keyboard.write a program to find out what was the date on 1st January of that year


#include
#include
void main()
{
long int nd,ld,td,fd,year;
clrscr();
printf("enter the year");
scanf("%ld",&year);
nd=(year-1)*365;
ld=(year-1)/4-(year-1)/100+(year-1)/400;
td=nd+ld;
fd=td%7;

if(fd==0)
printf("\n monday");
if(fd==1)
printf("\n tuesday");
if(fd==2)
printf("\n wednesday");
if(fd==3)
printf("\n thursday");
if(fd==4)
printf("\n friday");
if(fd==5)
printf("\n saturday");
if(fd==6)
printf("\n sunday");
getch();
}