Showing posts with label c programing. Show all posts
Showing posts with label c programing. Show all posts

pattern_1

/*
1
22
333
4444
55555*/

#include
#include

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

check number is armstrong

//Enter one number and check it is armstrong no or not
#include
#include
void main()
{
int no,i,r=0,d;
clrscr();
printf("\n Enter The No :- ");
scanf("%d",&no);
while(no>0)
{
d=no%10;
no=no/10;
r=r+(d*d*d);
}
if(r==0)
{
printf("\n No is Armstrong");
}
else
{
printf("\n No Is Not Armstrong");
}
getch();
}

prime number

/* except one no from user and find it is prime or not */

#include
#include

void main()
{
int i=2,n;
clrscr();
printf("enter no:-");
scanf("%d",&n);
while(i<=n-1)
{
if(n%i==0)
{
printf("no is NOT prime");
break;
}
i++ ;
}
if(i==n)
{
printf("no is prime");
}
getch();
}

factorial number

/*except one no from user and display its factorial*/

#include
#include

void main()
{
int no,i,fact=1;
clrscr();
printf("\n Enter The No :- ");
scanf("%d",&no);
for(i=no;i>=1;i--)
{
fact=fact*i;
}
printf("\n factorial of this number is :- %d",fact);
getch();
}

sum of each digit

*/ except one no from user and display sum of each digit */

#include
#include

void main()
{
int no,d,sum=0;
clrscr();
printf("\n Enter The No :- ");
scanf("%d",&no);
while(no>0)
{
d=no%10;
no=no/10;
sum=sum+d;
}
printf("\n The Sum Digit :- %d",sum);
getch();
}

reverse of number

/* except one no from user and display reverse of it.*/

#include
#include

void main()
{
long int no,d,rev=0;
clrscr();
printf("\n Enter The No :- ");
scanf("%ld",&no);
while(no>0)
{
d=no%10;
no=no/10;
rev=d+(rev*10);
}
printf("\n Reverse No Is :- %ld",rev);
getch();
}

print the total of 1-2+3-4+5-6+7-8+9-10...

/* print the total of 1-2+3-4+5-6+7-8+9-10 */

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

print the total of 1/2 + 2/3+......+9/10. ...

/* print the total of 1/2 + 2/3+......+9/10. */

#include
#include
void main()
{
float i=1,j=2;
float tot=0;
clrscr();
while(i<10)
{
tot=tot+(i/j);
printf("\n%f",i/j);
i++;
j++;
}
printf("\nsum is %f",tot);
getch();
}

print 2,11,20,28,35,41,46,50,53,55,56...

/* print 2,11,20,28,35,41,46,50,53,55,56 */

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

print 1,10,2,9,3,8,4,7,5,6...

/* print 1,10,2,9,3,8,4,7,5,6 /*

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

}
getch();
}

print 1,3,5,7,9...

/*print 1,3,5,7,9,11 */

#include
#include
void main()
{
int no=1,i;
clrscr();
printf("enter the number :");
scanf("%d",&i);
while(no<=i)
{
printf(" %d",no);
no=no+2;
}

getch();
}

leap year or not

/* DETERMINE WHETHER THE YEAR IS LEAP YEAR OR NOT.*/

#include
#include


void main()
{
int yr;
clrscr();
printf("\n Enter the year=>>");
scanf("%d",&yr);

if(yr%400==0 || (yr%100 != 0 && yr%4 == 0))
{


printf("\nleap year");
}
else
{
printf("\nnot a leap year");
}

getch();
}

circle ,rectangle,square and triangle using switch case

/*write a program to calculate the area of circle ,rectangle,square and triangle in one program with using switch case /*

#include
#include
void main()
{
int a=0,b,pi=3.14,r,h,n;
clrscr();
printf("enter r:");
scanf("%d",&r);
printf("enter b:");
scanf("%d",&b);
printf("enter h:");
scanf("%d",&h);
printf("\nenter 1 for circle\nenter 2 for square\nenter 3 for rectangle\nenter 4 for triangle\n");
printf("enter choice:");
scanf("%d",&n);

switch (n)
{
case 1:
a=pi*r*r;
printf("area of circle is %d",a);
break;
case 2:
a=4*b;
printf("area of square is %d",a);
break;
case 3:
a=2*b*h;
printf("area of rectangle is %d",a);
break;
case 4:
a=(b/2)*h;
printf("area of triangle is %d",a);
break;
default:
printf("bug");
break;
}
getch();
}

input mark and calculate the percentage

/* input five sub mark and calculate the percentage */

#include
#include
void main()
{
int m1,m2,m3,m4,m5,tot;
float per;
clrscr();
printf("\n Enter The Mark M1 :- ");
scanf("%d",&m1);
printf("\n Enter The Mark M2 :- ");
scanf("%d",&m2);
printf("\n Enter The Mark M3 :- ");
scanf("%d",&m3);
printf("\n Enter The Mark M4 :- ");
scanf("%d",&m4);
printf("\n Enter The Mark M5 :- ");
scanf("%d",&m5);
tot=m1+m2+m3+m4+m5;
per=tot/5;
printf("\n Percentage = %f",per);
if(per>=70)
{
printf("\n");
printf("\n Distinction");
}
else if(per<=69 && per>=60)
{
printf("\n");
printf("\n First Class");
}
else if(per<=59 && per>=50)
{
printf("\n");
printf("\n Second Class");
}
else if(per<=49 && per>=40)
{
printf("\n");
printf("\n Pass Class");
}
else
{
printf("\n");
printf("\n Fail");
}
getch();
}

character in lower case to upper case

/* get a character in lower case from user and display it in upper case. */

#include
#include
void main()
{
char ch;
clrscr();
printf("\n input lower case character :");
scanf("%c",&ch);
ch=ch-32;
printf("In Upeer Case : %c",ch);
getch();

}

maximum among 2 numbers

/* input 2 number and print the maximum among them.(with conditional operator) */

#include
#include
void main()
{
int x,y,max;
clrscr();
printf("enter number of value1");
scanf("%d",&x);
printf("enter number of value2");
scanf("%d",&y);
max = (x>y?x:y);
printf("maximum is %d",max);
getch();
}

rupees converted into dollar

/* input a rupees and prints its value converted into dollar */

#include
#include
void main()

{
float rs,dollar;
clrscr();
printf("enter rupees:");
scanf("%f",&rs);
dollar = rs/45;
printf("%f",dollar);
getch();
}

area of triangle

/* calculate the area of triangle */

#include
#include

void main()

{
float t,b,h;
clrscr();
printf("enter value for b:");
scanf("%f",&b);
printf("enter value for h:");
scanf("%f",&h);
t=(float)0.5*b*h;
printf("%f",t);
getch();
}

area of circle

/* calculate the area of circle. */

#include
#include
void main()

{
float r,a;
clrscr();
printf("enter value for circle:");
scanf("%f",&r);
a=3.1416*r*r;
printf("%f",a);
getch();
}

verify the formula - 4

/* verify the formula t=((v+s)+(l-m)*l) */

#include
#include
void main()

{
int v,s,l,m,t;
clrscr();
printf("t=((v+s)+(l-m)*l)");
printf("\nenter value of s:");
scanf("%d",&s);
printf("enter value of v:");
scanf("%d",&v);
printf("enter value of l:");
scanf("%d",&l);
printf("enter value of m:");
scanf("%d",&m);
t=(((v+s)+(l-m)*l));
printf("ans:%d",t);
getch();
}