pages

Monday, 31 May 2021

c-program to find the roots of the quadratic equations | c-programming

Program to find the Roots of quadratic equation.

In this program ,we will now takes input as the coefficients of quadratic equations by the user and calculate the roots of the quadratic equations in c-programming.  


#include<stdio.h>
#include<conio.h>
void main()
{
         int a,b,c,D;
         float x,y;
         printf("enter the cofficients of x^x , x and constant:-");
         scanf("%d %d %d",&a,&b,&c);
         D=b*b-(4*a*c);
         if(D<0){
                  printf("\n roots are not possible i,e imaginary roots ");
         }
         if(D==0){
                  printf("\n both roots are equals");
                  x=(-1*b)/(2*a);
                  y=(-1*b)/(2*a);
                  printf("\n the roots are %.2f and %.2f",x,y);
         }
         if(D>0){
                  printf("\n the roots are real and distinct ");
                  x=((-1*b)+sqrt(D))/(2*a);
                  y=((-1*b)-sqrt(D))/(2*a);
                  printf("\n the Roots are %.2f and %.2f",x,y);
         }
         getch();
}

output:-




For more c-programming:-


Sunday, 30 May 2021

c-program to calculate the sum of five number by using pointer in c-programming| c-language

program to calculate the sum of all five number by using pointer in c-programming.

In this program ,we will now  takes input five numbers by the user and print the sum of all five number by using pointer in c-programming.



#include<stdio.h>
#include<conio.h>
void main()
{
         int i,a[5],sum=0;
         int *p;
         p=&a[0];
         printf("enter the five numbers:-");
         for(i=0;i<=4;i++){
                  scanf("%d",p);
                  p++;
         }
         p=&a[0];
         printf("\n the number are follow:-");
         for(i=0;i<5;i++){
                  printf("%d ",*p);
                  sum=sum+*p;
                  p++;
         }
         printf("\n the sum of the numbers is %d",sum);
         getch();
}

output-





For more c-programming:-


Friday, 28 May 2021

c-program to print the name ,class and roll of the user by using structure in c-programming | c-language

 program to make a students file and prints the name ,class and roll number in c-programming.

program to takes the students name , class and roll by the user and prints them by using structure in c-programming languages.

#include<stdio.h>
#include<conio.h>
struct student
{
         char name[20];
         int roll;
         int classes;
};
struct student input()
{
    struct student b;
    printf("enter the name of student,roll and class:-");
    gets(b.name);
    fflush(stdin);
    scanf("%d",&b.roll);
    scanf("%d",&b.classes);
    return(b);
}
void display(struct student s)
{
         printf("\n name:-%s roll:-%d class:-%d",s.name,s.roll,s.classes);
}
void main()
{
         struct student b1;
         b1=input();
         display(b1);
         getch();
}

output:-




For more c-programming:-















Wednesday, 26 May 2021

c-program to print the reverse of the number by using pointer | c-programming

program to reverse the number by using pointer in c-programming

In this program ,we will now  takes input as a number and print the reverse of the number by using pointer in c-programming.



 //program to reverse of the number by using pointer
#include<stdio.h>
#include<conio.h>
void main()
{
         int n,rev,num;
         int *n1,*rev1,*num1;
         n1=&n,rev1=&rev,num1=&num;
         *num1=0;
         printf("enter the number:-");
         scanf("%d",&n);
         while(*n1!=0){
                  *rev1=*n1%10;
                  *num1=*num1*10+*rev1;
                  *n1=*n1/10;
         }
         printf("\n the reverse of the number is %d",*num1);
         getch();
}


output:



For more c-programming:-


















Friday, 21 May 2021

c-program to calculate the length of string using pointer | c-programing

 Program to calculate the length of string using pointer in c-programming

In this program , we will now taking  input as a string and calculate the length of string by using pointer.

pointer : pointer is a variables that stores address of another variables.

#include<stdio.h>
#include<conio.h>
void main()
{
         char str[50];
         char *i,count=0;
         i=str;
         printf("enter the string:-");
         gets(str);
         while(*i!='\0'){
                  count++;
                  i++;
         }
         printf("\n the length of the string is %d:-",count);
         getch();
}

output:-



For more c-programming:-















c-program to print the 10 number and also print the reverse of each number | c-programming languages

 program to print the 10 numbers and also print the reverse of each number in c-proramming 

In this program we will now input 10 numbers form the user by using array and print the number and also print the reverse of the each number in c-programming. 


//program to print the 10 number and also print reverse of the number
#include<stdio.h>
#include<conio.h>
void main()
{
         int a[10],b[10],i,n,num=0,rev=0;
         printf("enter the 10 numbers:-");
         for(i=0;i<10;i++)
                  scanf("%d",&a[i]);
         for(i=0;i<10;i++){
                  n=a[i];
                  num=0;
                  while(n!=0){
                           rev=n%10;
                           num=num*10+rev;
                           n=n/10;
                  }
                  b[i]=num;
         }
         for(i=0;i<10;i++)
                  printf("the number is %d and reverse is %d\n",a[i],b[i]);
         getch();
}

output:-




For more c-programming:-


















Wednesday, 19 May 2021

c-programming to print the sum of even and odd number in 10 numbers by using array | c-programming

 program to print the sum of even and odd number in 10 numbers in array in c-programming

In this program we will now takes 10 numbers form the user and print the sum of even and odd number and also print the even and odd in c-programming.

#include<stdio.h>
#include<conio.h>
void main()
{
         int a[10],i,even,odd,sum=0,evensum=0,oddsum=0;
         printf("enter the 10 number:-");
         for(i=0;i<=9;i++){
                  scanf("%d",&a[i]);
         }
         for(i=0;i<=9;i++){
                  sum=sum+a[i];
                  if(a[i]%2==0){
                           printf("even number is %d\n",a[i]);
                           evensum=evensum+a[i];
                  }
                  else{
                           printf("odd number is %d\n",a[i]);
                           oddsum=oddsum+a[i];
                  }
         }
         printf("\n the sum of even number is %d",evensum);
         printf("\n the sum of odd number is %d",oddsum);
         printf("\n the sum of the number is %d",sum);
         getch();
}

output:-



For more c-programming:-


















c-program to find the biggest number in 10 numbers by using array | c-programming

Program to print the 10 number  and find  the biggest number  in 10 numbers in c-programming

In this program we will now input 10 number by the user using array and find the biggest number in 10 number in c-program

//program to find the biggest elements
#include<stdio.h>
#include<conio.h>
void main()
{
         int a[10],i,max;
         printf("enter the number:-");
         for(i=0;i<=9;i++){
                  scanf("%d",&a[i]);
         }
         max=a[0];
         for(i=0;i<=9;i++){
           printf("%d ",a[i]);
            if(max<a[i])
                  max=a[i];
         }
         printf("\n the biggest number in the array is %d",max);
         getch();
}

output:-


For more c-programming:-




















Sunday, 16 May 2021

c-program to swap three number by using pointer in c-languages

 program to swap three number by using  pointer in c-programming:

In this program, we will now takes three number from the user and swap this three number by using pointer.

#include<stdio.h>
#include<conio.h>
int fun(int *,int *,int *);
void main()
{
         int x,y,z;
         printf("enter the three number:-");
         scanf("%d %d %d",&x,&y,&z);
         printf("\n before swapping:x=%d y=%d and z=%d",x,y,z);
         fun(&x,&y,&z);
         printf("\n after swapping: x=%d y=%d and z=%d",x,y,z);
         getch();
}
int fun(int *a,int *b,int *c)
{
         int i;
         i=*b;
         *b=*a;
         *a=*c;
         *c=i;
}


output:-



For more c-programming


















c-program to calculate the area of triangle by using pointer | c-programming

 If the length of the sides of a triangle are denoted by a,b,c and  then what is the area of the triangle by using pointer ?


In  this program , we have to taking  three input i,e sides of the triangles form the user and calculate the area of the triangle .

#include<stdio.h>
#include<conio.h>
void main()
{
         float s=0,a,b,c,area=0;
         float *x,*y,*z,*sum,*area1;
         printf("enter the three number:-");
         scanf("%f %f %f",&a,&b,&c);
         x=&a,y=&b,z=&c,sum=&s,area1=&area;
         s=(a+b+c)/2;
         printf("\n the area of the triangle are follow");
         area=sqrt(s*(s-a)*(s-b)*(s-c));
         printf("\n the solution is %.2f",*area1);
         getch();
}

output :-

                              


For more c-programming:-

Tuesday, 11 May 2021

c-program to print table of any number by using pointer | c-programming

 Program to print the table of natural number by using pointer  in c-programming



In this program we will now taking input n natural number by the user and print table of the natural number  in c-programming. 








#include<stdio.h>
#include<conio.h>
void main()
{
         int n,i;
         int *x,*y;
         x=&n,y=&i;
         printf("\n enter the number:-");
         scanf("%d",&n);
         for(i=1;i<=10;i++){
                  printf("\n%d*%d=%d",*x,*y,(*x)*(*y));
         }
         getch();
}























output:-







For more c-programming:-





























c-program to check which string is plaindrome or not | c-programming

program to check string is plaindrome in c-programming 

In this program ,we will check which string is plaindrome or not by taking input string form the user .

#include<stdio.h>
#include<conio.h>
void main()
{
   char str[20];
   int i,l;
   printf("enter the string:-");
   gets(str);
   l=strlen(str);
   for(i=0;i<l/2;i++){
         if(str[i]!=str[l-i-1]){
         printf("not a plaindrome");
         break;
         }
   }
    if(i==l/2)
         printf("string is plaindrome");
   getch();
}

output:-





For more c-programming:-























Sunday, 9 May 2021

c-program to print all prime number between 1 to 300 numbers | c-programming

 Program to print all prime number between  1 to 300 in c-programming:-

In this program , we will now taking  input from the user and print  all prime number between 1 to 300 numbers using for loop.

prime-number:- A number which is only divisible by 1 and itself is called prime number .

#include<stdio.h>
void main()
{
         int i,n;
         for(n=1;n<=300;n++){
                  for(i=2;i<=n-1;i++){
                           if(n%i==0)
                                    break;
                  }
                  if(i==n)
                           printf("%d ",i);
         }
         return(0);
}

output:-



For more c-programming:-
















Wednesday, 5 May 2021

c-program to calculate factorial of a number by using pointer | c-programming

program to calculate the factorial of the any number by using pointer 

In this program , we will now calculate the factorial of the number by taking input from the user by using  pointer in  c-programming


#include<stdio.h>
#include<conio.h>
int factorial(int *, int*);
void main()
{
         int fact,num;
         printf("enter the number:-");
         scanf("%d",&num);
         factorial(&num,&fact);
         printf("\n the factorial of the %d is %d",num,fact);
         getch();
}
int factorial(int *n,int *f)
{
         int i;
         *f=1;
         for(i=1;i<=*n;i++)
                  *f=*f*(i);
                  return(*f);
}

output:-



For more c-programming:-






















c-program to calculate the table of any number by using pointer | c-programming

program to calculate the table of any number in c-programming 

In this program ,we will now calculate the table of any number by using pointer in c-program by taking input from the user .


#include<stdio.h>
#include<conio.h>
void main()
{
         int n,i;
         int *x,*y;
         x=&n,y=&i;
         printf("\n enter the number:-");
         scanf("%d",&n);
         for(i=1;i<=10;i++){
                  printf("\n%d*%d=%d",*x,*y,(*x)*(*y));
         }
         getch();
}

output:-
















Tuesday, 4 May 2021

c-program to calculate sum and average of five number by using pointer in c-programming

 program to receives 5 integers and return the sum, average of these numbers by using pointers in c-programming.

In this c-program , we calculate to Find the Sum and Average of a number by Using the Pointer by taking input from the user .

#include<stdio.h>
#include<conio.h>
void main()
{
         float a[5],ave=0,sum=0;
         int i;
         float *pa,*pave=0,*psum=0;
         pa=a;
         pave=&ave,psum=&sum;
         printf("enter the number:-");
         for(i=0;i<5;i++){
                  scanf("%f",(pa+i));
                  *psum=*psum+*(pa+i);
         }
         printf("\nthe sum of the number is %.2f",*psum);
         *pave=*psum/5;
         printf("\nthe average of the number is %.2f",*pave);
         getch();
}

output:-



Another way to solve this problem are follow :-


#include<stdio.h>
#include<conio.h>
void input(int *p,int  size);
void display(int *p,int size);
void main()
{
         int a[5];
         input(a,5);
         display(a,5);
         getch();
}
void input(int *p,int  size)
{
         int i;
         printf("enter %d number",size);
         for(i=0;i<size;i++)
                  scanf("%d",(p+i));
}
void display(int *p,int size)
{
         int i,sum=0;
         float ave=0;
         printf("\nthe number are as follow:-");
         for(i=0;i<size;i++){
                  printf("%d ",*(p+i));
                  ave=ave+*(p+i);
                  sum=sum+*(p+i);
         }
         printf("\n the sum of the number is %d",sum);
         ave=ave/5.00;
         printf("\n \naverage of the number is %.2f",ave);
}

Output :- 




















c-program to swap two number by using pointer | c-programming

program to swap two number by using pointer in c-programming 

In this program ,we will now swap two number by using pointer in c-program by taking input form the user.
When we call the function, we pass the  address of the variable, so this method is called “Call by Reference“.


when we  ask the user to enter the values for variable a and b. We passes the address of variable a and b to the function swap().
Inside the function swap() we take a local variable i. Since address of variable a and b are passed to swap() function , we take 2 pointer variables *x and *y. Pointer variable x holds the address of a and pointer variable y holds the address of b. Using below logic we swap the values present at address a( or x ) and b( or y ).

#include<stdio.h>
#include<conio.h>
int swap(int *,int *);
void main()
{
         int a,b;
         printf("enter the two number:-");
         scanf("%d %d",&a,&b);
         printf("\nbefore swapping:- a=%d and b=%d",a,b);
         swap(&a,&b);
         printf("\nafter swapping:- a=%d and b=%d",a,b);
         getch();
}
int swap(int *x,int *y)
{
         int i;
         i=*x;
         *x=*y;
         *y=i;
}


output:-




For more c-programming:-