pages

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:-