Saturday, 30 March 2019

print the number which existence

#include<stdio.h>
main()
{
int i,n,number[5];
for(i=0;i<5;i++)
scanf("%d",&number[i]);
for(i=0;i<5;i++)
{
if(n==number[i])
printf("%d",number[i]);
}
}

arry2

#include<stdio.h>
main()
{
int i,number[5];
for(i=0;i<5;i++)
scanf("%d",&number[i]);
for(i=4;i>=0;i--)
printf("%d",number[i]);
}

arry1

#include<stdio.h>
main()
{
int i,number[5];
for(i=0;i<5;i++)
scanf("%d",&number[i]);
for(i=0;i<5;i++)
printf("%d",number[i]);
}

print even number by arry

#include<stdio.h>
main()
{
int i,number[5];
for(i=0;i<5;i++)
scanf("%d",&number[i]);
for(i=0;i<5;i++)
{
if(number[i]%2==0)
printf("%d",number[i]);
}
}

Wednesday, 27 March 2019

Write a C program to read weekday number and print weekday name using switch

#include<stdio.h>
main()
{
    int Weekday_Number;
    printf("Enter Weekday Number:");
    scanf("%d",&Weekday_Number);
    switch(Weekday_Number)
    {
        case 1:
        printf("Saturday");
        break;
        case 2:
        printf("Sunday");
        break;
        case 3:
        printf("Monday");
        break;
        case 4:
        printf("Tuesday");
        break;
        case 5:
        printf("Wednesday");
        break;
        case 6:
        printf("Thusday");
        break;
        case 7:
        printf("Friday");
        break;
        default:
        printf("error");
    }
}

Tuesday, 19 March 2019

* * * * * *

#include<stdio.h>
main()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}

1 2 2 3 3 3

#include<stdio.h>
main()
{
int i=1,j;
while(i<=3)
{
    j=1;
    while(j<=i)
    {
        printf("%d",i);
        j++;
    }
    printf("\n");
    i++;
}
}

1 1 2 1 2 3

#include<stdio.h>
main()
{
int i=1,j;
while(i<=3)
{
    j=1;
    while(j<=i)
    {
        printf("%d",j);
        j++;
    }
    printf("\n");
    i++;
}
}

Factorial

#include<stdio.h>
main()
{
int i,n,fact=1;
printf("Enter an integer:");
scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("Factorial of %d=%d",n,fact);
}

LCM of twonumbers

#include<stdio.h>
main()
{
int n1,n2,lcm;
printf("Enter two integer:");
scanf("%d%d",&n1,&n2);
lcm=(n1>n2)?n1:n2;
while(1)
{
if(lcm%n1==0 && lcm%n2==0)
{
printf("LCM of %d and %d is %d",n1,n2,lcm);
break;
}
++lcm;
}
}

GCD of two numbers

#include<stdio.h>
main()
{
int n1,n2,i,gcd;
printf("Enter two integer:");
scanf("%d%d",&n1,&n2);
for(i=1;i<=n1&&i<=n2;++i)
{
if(n1%i==0 && n2%i==0)
gcd=i;
}
printf("GCD of %d and %d is %d",n1,n2,gcd);
}

Fibonacci Series

#include <stdio.h>
main()
{
    int  fib1=0,fib2=1,fib3,limit,count=0;
    printf("Enter the limit to generate the Fibonacci Series:");
    scanf("%d",&limit);
    printf("Fibonacci Series is ...\n");
    printf(" %d",fib1);
    printf(" %d",fib2);
    count=2;
    while(count<limit)
    {
        fib3=fib1+fib2;
        count++;
        printf(" %d",fib3);
        fib1=fib2;
        fib2=fib3;
    }
}

sum of the series 1^3+2^3+3^3+-----+n^3

#include<stdio.h>
main()
{
int i,n,sum=0;
printf("Enter the max. value of series:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i*i*i);
}
printf("Sum of the series=%d",sum);
}

sum of the series 1^2+2^2+3^2+----+n^2

#include<stdio.h>
main()
{
int i,n,sum=0;
printf("Enter the max. value of series:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i*i);
}
printf("Sum of the series=%d",sum);
}

sum of the series 1+2+3+-----+n

#include<stdio.h>
main()
{
int i,n,sum=0;
printf("Enter the max. value of series:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i);
}
printf("Sum of the series=%d",sum);
}

prime number

#include <stdio.h>
main()
{
   int i,n,p=0;
   printf("Enter an integer:");
   scanf("%d",&n);
   for(i=1; i<=n;i++)
   {
      if(n%i==0)
         p++;
   }
   if(p==2)
      printf("%d is a prime number",n);
   else
      printf("%d is not a number",n);
}

Monday, 18 March 2019

Number of digits

#include<stdio.h>
main()
{
int n,count=0;
printf("Enter an integer:");
scanf("%d",&n);
while(n>0)
{
n=n/10;
count=count+1;
}
printf("Number of digits of %d=%d",n,count);
}

sum of digits

#include <stdio.h>
main()
{
   int p,q,r,sum=0;
   printf("Enter an integer:");
   scanf("%d",&p);
   q=p;
   while(q!=0)
   {
      r=q%10;
      sum=sum+r;
      q=q/10;
   }
   printf("Sum of digits of %d = %d\n",p,sum);
}

Monday, 4 March 2019

write a program using switch and if statements to coma customerpute the net amount to be paid by customer

#include<stdio.h>
main()
{
    float a;
    char ch;
    printf("Enter amount: ");
    scanf("%f",&a);
    printf("Enter item name for Mill 'm' for Handloom 'h': ");
    scanf("%s",&ch);
    if(a>0&&a<=100)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount =%.2f",a);
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a-=(a*0.05)));
                break;
            }
        }
    }
    else if(a>=101&&a<=200)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount = %.2f",(a-=(a*0.05)));
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a-=(a*0.075)));
                break;
            }
        }
    }
    else if(a>=201&&a<=300)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount = %.2f",(a-=(a*0.075)));
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a-=(a*0.1)));
                break;
            }
        }
    }
    else if(a>300)
    {
        switch(ch)
        {
        case 'm':
            {
                printf("Amount = %.2f",(a=(a*0.1)));
                break;
            }
        case 'h':
            {
                printf("Amount = %.2f",(a=(a*0.15)));
                break;
            }
        }
    }
}

Sunday, 3 March 2019

sqrt of any number from 0 to 9.9

#include<stdio.h>
#include<math.h>
main()
{
float sq,sum,i,j;
printf("Number\t");
j=0.1;
loop3:
printf("%.2f\t",j);
j=j+0.1;
if(j<1)
goto loop3;
printf("\n");
i=1;
loop1:
printf("%.2f\t",i);
j=0.1;
loop:
sum=i+j;
sq=sqrt(sum);
printf("%.2f\t",sq);
j=j+0.1;
if(j<1)
goto loop;
i=i+1;
if(i<=9)
{
printf("\n");
goto loop1;
}
}

Saturday, 2 March 2019

eligible for the admission

#include<stdio.h>
main()
{
    int Math,Phy,Chem,Total,Total_MP;
    printf("Enter the number of Math:");
    scanf("%d",&Math);
    printf("Enter the number of Phy:");
    scanf("%d",&Phy);
    printf("Enter the number of Chem:");
    scanf("%d",&Chem);
    Total=Math+Phy+Chem;
    Total_MP=Math+Phy;
    if(Math>=60&&Phy>=50&&Chem>=40&&Total>=200)
    printf("The candidate is eligible for the admission");
    else
    {
        if(Total_MP>=150)
            printf("The candidate is eligible for the admission");
        else
            printf("The candidate is not eligible for the admission");
    }
}

A set of two linear eqn and find x1 and x2.

#include<stdio.h>
main()
{
int a,b,c,d,m,n;
float x1,x2;
printf("Enter the value of a,b,c,d,m,n:");
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&m,&n);
if((a*d-c*b)!=0)
{
x1=(m*d-b*n)/(a*d-c*b);
x2=(n*a-m*c)/(a*d-c*b);
printf("\n The value of x1=%f\n The value of x2=%f",x1,x2);
}
else
printf("The division is not possible and result is an abrupt value");
}

the programe evaluates the sqrt for 5 number using goto statement

#include<stdio.h>
#include<math.h>
main()
{
double x,y;
int count;
count=1;
printf("Enter FIVE real value in a line\n");
read:
scanf("%lf",&x);
printf("\n");
if(x<0)
printf("value %d is negative\n",count);
else
{
y=sqrt(x);
printf("%lf\t%lf\n",x,y);
}
count=count+1;
if(count<=5)
goto read;
printf("End of computation");
}