pages

Friday, 30 April 2021

c-program to reverse the string without using strrev function | c-programming

 program to reverse of the number without using strrev function 

In this program ,we will takes input as a string by the user and reverse the string  without using strrev  function .


#include<stdio.h>
#include<conio.h>
void main()
{
   char str[20],temp;
   int i,l;
   printf("enter the string:-");
   gets(str);
   for(l=0;l<=str[l];l++);
   for(i=0;i<l/2;i++){
         temp=str[i];
         str[i]=str[l-i-1];
         str[l-i-1]=temp;
   }
   printf("\n the reverse of the string is %s:-",str);
   getch();
}

output:-


For more c-programming:-













Thursday, 29 April 2021

c-program to copy the string without using strcmp fuction by using pointer in while loop

program to copy the string without using strcmp funtion by using pointer. 

In this program, we will now copy the string without using  strcmp function by using pointer by taking input form the user.


#include<stdio.h>
#include<conio.h>
int copy(char *s2,char *s1);
void main()
{
         char str1[50],str2[50];
         printf("enter the string:-");
         gets(str1);
         copy(str2,str1);
         printf("\n first string of str1 is :-%s",str1);
         printf("\n second string of str2 is:- %s",str2);
         getch();
}
int copy(char *s2,char *s1)
{
         while(*s1!='\0'){
                  *s2=*s1;
                  s1++;
                  s2++;
         }
         s2='\0';
}

output:-




For more c-programming:-

1.











c-program to calculate the length of the string by pointer using while loop .

program to calculate the length of the string by pointer using while loop

In this  program ,we will  now calculate the length of the  string by pointer using while loop by taking taking string  as  a input from the user.
pointer :- pointer is  a variable which contain address of another variable.

  • gets() is used to accept string with spaces.
  • the base address is stored in the variable i . Once the base address is obtained in i , *i would  yield  the value at this address .
  • Inside while loop we are going to count single letter and incrementing pointer further till we get null character.

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











Monday, 26 April 2021

c-program to transform a string into its uppercase without using strupr() function | c-programming

Program to transform a string into its uppercase without using strupr() function in c-programming.


In this program allows the user to enter any string or character array. Next, it will use For Loop to iterate every character in that string, and convert them to Uppercase.

The value of a in ASCII is 97, if we subtract 32 it becomes 65 which is ASCII value of A.
So, All lowercase characters ASCII value is from 97 to 122 and if we subtract 32 in each lowercase character only then it will become uppercase character.

//program to transform string into uppercase
#include<stdio.h>
#include<conio.h>
void main()
{
         char str[50];
         int i;
         printf("enter the string:-");
         gets(str);
         for(i=0;str[i];i++){
                  if(str[i]>='a'&& str[i]<='z')
                           str[i]=str[i]-32;
         }
         printf("\n the string is %s",str);
         getch();
}


c-program to check Armstrong number | c-programming

program to check Armstrong number  

In this program , we will now check weather a number is Armstrong number by taking  input form the user .
Armstrong number:- A positive number is called an Armstrong number if the  sum of the cubes if the digits is equal to the number itself.
In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153:- 1*1*1 + 5*5*5+3*3*3

//program to check armstrong
#include<stdio.h>
#include<conio.h>
void main()
{
         int n,x,s=0,temp;
         printf("enter the number:-");
         scanf("%d",&n);
         temp=n;
         while(n!=0){
                  x=n%10;
                  s=s+(x*x*x);
                  n=n/10;
         }
         if(temp==s)
                  printf("\n number is armstrong");
         else
                  printf("\n  number is not armstrong");
         getch();
}

output:- 




For more  c-programming:-


















Sunday, 25 April 2021

c-program to calculate the length of sting using strlen function.| c-programming

 Porgram to calculate the length of string using strlen function.

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

string is not but a collection of a character terminated at null '\0'.

strlen function:- The strlen function calculates the length of a string .

strlen function takes a string as a argument and gives length of  the string.


#include<stdio.h>
#include<conio.h>
void main()
{
   char str[20];
   int l;
   printf("enter the string\n");
   gets(str);
   l=strlen(str);
   printf("the length of the string is %d",l);
   getch();
}


output:-  

                   


For more c-programming :-

1 .c-program to calculate the length of string without using strlen function

2 .strlwer funtion convert string into lowercase

















c-program to count the vowel in the string | c-programming

 program to count the vowel in the string in c-programming.

In this program , we will write  a c-program to count the vowel in the string by taking string by the user.
 In the program both lower and upper case are considered i.e., 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u' and 'U'. In this program we check every character in the input string, if it's a vowel then counter is incremented by one, consonants and special characters are ignored.


//program to count the vowel in the string
#include<stdio.h>
#include<conio.h>
void main()
{
         char str[40],v[]="aeiouAEIOU";
         int i,j,count=0;
         printf("enter the string:-");
         gets(str);
         for(i=0;str[i];i++){
                  for(j=0;v[j];j++){
                           if(str[i]==v[j]){
                                    count++;
                                    break;
                           }
                  }
         }printf("no of vowel in the string is %d",count);
         getch();
}


output:-



for more c-programming:-

1.c-program to count the length of string without using strlen function
















Monday, 19 April 2021

c-program | program to print all prime number from 1 to n natural number in c-programming

program to print the all prime number form 1 to n natural number.

we have first to know that what is prime number , A number which is only divisible by 1 and itself is called prime number.

In this  program , we will takes input from the user to print all prime numbers from 1 to N. The logic behind implement this program is that - Run loop from 1 to N and check each value in another loop, if the value is divisible by any number between 2 to num-1 (or less than equal to num/2) - Here num is the value to check it is prime of not.


 #include<stdio.h>
 #include<conio.h>
 void main()
 {
      int i,num,j;
      printf("enter the numbre:-");
      scanf("%d",&num);
      for(i=2;i<=num;i++){
         for(j=2;j<=num-1;j++){
                  if(i%j==0){
                           break;
                  }
         }
         if(i==j)
                  printf("%d ",j);
      }
      getch();
 }


output:-  enter the number num=35

prime  number are: 2,3,5,7,11,13,17,19,23,29,31


For more c-programming:-

1.c-program to check which number is prime or not

2.c-program to check plaindrome or not

3.c-program to swap two number without using third variable


Sunday, 18 April 2021

c-program to compare two string | c-programming

program to compare two string using strcmp function. 

In this program, we will now first take two string as input from user using gets function and store it in two character array. Now, we have to compare two strings by using strcmp function.
The strcmp() compares two strings, character by character. If the first character of both strings is equal then the next character of both strings are compared. This continues until the corresponding characters of two strings are different or a null character ‘\0’ is reached.
Do not forget to include ‘string.h’ header file.


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
   char s1[20],s2[20];
   printf("\n enter the first string:-");
   gets(s1);
   printf("enter the second string:-");
   gets(s2);
   if(strcmp(s1,s2)==0)
         printf("\n the two string are same");
   else
         printf("the two string are not same");
   getch();
}



output:-

 


For more c-programming:-

program to count the vowel in the string

program to count the length of string by using strlen function










c-program to calculate length of string without strlen function.| c-programming

 c-program to calculate the length of the string without using strlen function.

In this program, we will now allow the user to enter the any string or character array and It will gives the length of the string  without using strlen function.
string is nothing but one dimensional array of character which is terminated by a null character '\o'.
 In this program, we have the length of sting so, we need to loop and count all words and spaces in the loop until '\0' character is matched

#include<stdio.h>
#include<conio.h>
void main()
{
   char str[20];
   int i;
   printf("enter a string\n");
   gets(str);
   for(i=0;i<str[i];i++);
   printf("length of the string is %d",i);
   getch();
}

output:- 



for more c-programing practice:-

1.c-program to calculate the length of string using strlen function

2.c-program to string into lowercase

3.program to count the vowel in the string.








strlwr-funtion | c-program to convert all string into lowercase.| c-programming

 c-program to convert all into small lowercase.

In this program ,we will taking input string by the user and  it covert all into lowercase(small letters)

strlwer()  function:- the strlwr() function is used to convert a given string into lowercase.

strlwr() function is not standard function  which may not available in standard libary in c


#include<stdio.h>
#include<conio.h>
void main()
{
   char str[20];
   printf("enter a string\n");
   gets(str);
   printf("string is %s",strlwr(str));
   getch();
}

Output:-


For more c-programming:-
1.c-program to calculate the length of string using strlen function

2 .c-program to compare the two string





c-program | program to print all even and odd from 1 to n natural number in c-programming

 c-program to print the all even and odd number form 1 to n natural numbers

In this program, we will discuss the C program to display all even and odd  number from 1 to n natural number.
In this program, we are going to learn about how to find  odd or even numbers from 1 to given number using the while loop in the C language.
What is Even or Odd
When the number is divided by 2 and the the remainder becomes zero then the  number is called as the even number on the other sides when it is divided by 2 and the remainder  becomes 1 they are called odd numbers .

program to print even and odd number  from 1 to n natural number using while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
         int i,n;
         printf("enter the number\n");
         scanf("%d",&n);
         printf("\n even number \n");
         i=2;
         while(i<=n){
               printf("%d ",i);
               i=i+2;
         }
         printf("\nodd number\n");
         i=1;
         while(i<=n){
                  printf("%d ",i);
                  i=i+2;
         }
         getch();
}


output:-



 Another way to solve this program :-


/*program to print even number from 1 to n  by using while loop*/
#include<stdio.h>
#include<conio.h>
void main()
{
  int i=1,n;
  printf("enter the number");
  scanf("%d",&n);
  while(i<=n)
  {
           if(i%2==0){
                  printf("%d\n",i);
                  i++;
           }
           else{
                printf("%d ",i);
                i++;
           }
  }
  getch();
}

output :-  even number 2,4,6,........
                  odd number 1,3,5,7,9.........


For more c-programming :-

1.c-program to check which number is divisible by 2,3,9

2.c-program to check which number is divisible by 4,6,9.

3.c-program to check weather a number is prime or not

4.c-program to print all prime number form 1 to n natural number



































Saturday, 17 April 2021

c-program | program to check weather a number is divisible by 2,3,9 in c-language.

 program to check weather a number is divisible by 2,3,9 in c-programing?

In this program , we will now taking input from the number and to check weather a number is divisible by 2,3,9 in c-programming .


A number is exactly divisible by some other number if it gives 0 as remainder. To check if a number is exactly divisible by some number we need to test if it leaves 0 as remainder or not.


#include<stdio.h>
#include<conio.h>
main()
{
    int a;
    printf("enter a number");
    scanf("%d",&a);
    if(a%2==a%3==a%9==0)
        printf("%d is divisible by 2,3,9",a);
    else
        printf("%d is not divisible by 2,3,9",a);
    getch();
}

output:- 


        enter a number  a=36
     the 36 is divisible by  2,3,9.

For more c-programming :-

1.c-program check weather a number is divisible by 4,6,9.








Wednesday, 14 April 2021

Fibonacci series using recursion in c -programming | c language

Fibonacci series using recursion in c-program | Fibonacci series c-language recursion.

Fibonacci series is a series of the number where the third term is the sum of the previous two terms 

for example: 0,1,1,2,3,5,8,.....

The next number is found by the adding up the two numbers before it. The first two term are zero and one respectively.


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


output:- 






For more c-programming example:-



  










c-program to display Fibonacci series.| c-programming

C-Program to  print Fibonacci series .

Fibonacci series is a sequence of number where the next is the sum of the previous two terms . 

for example:- 0,1,1,2,,3,5,8,13,21,34,55 etc. The first two numbers of Fibonacci series are 0 and 1.

A simple For loop is used to display the series. Taking input from the user for the number of terms to display . 



#include<stdio.h>
#include<conio.h>
void main()
{
   int n,i,a=-1,b=1,c=0;
   printf("enter the number\n");
   scanf("%d",&n);
   for(i=0;i<n;i++){
         c=a+b;
         printf("%d ",c);
         a=b;
         b=c;
   }
   getch();
}

output:  






















Tuesday, 13 April 2021

c-program to calculate the sum of even and odd in 10 numbers | c-programming languages

 Q.no program to calculate the sum of the even and odd number in 10 natural number .

In this c-basic program, we will calculate the sum of the even and odd number from 10 natural number by taking input from the user .

if a number is divisible by 2 is even number. If condition will check weather the remainder of the  divisible by 2 is equal to  0 or 1.

if the remainder value is 0 then the number is even ,and the remainder value is 1 then odd number .



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

output:-









c-program to calculate the average of 10 numbers| c-programming| c programming

 program to calculate the average of 10 numbers in c-programing.

In this program, we will calculate the average of 10 number  by using loop and taking 10 numbers form the user. 


#include<stdio.h>
#include<conio.h>
void main()
{
   int a[10],i,s=0;
   float avg;
   printf("enter the 10 numbers\n");
   for(i=0;i<10;i++)
         scanf("%d",&a[i]);
   for(i=0;i<10;i++){
            s=s+a[i];
            avg=s/10.0;
   }
   printf("the average of 10 number is %0.2f",avg);
   getch();
}

output: 














c-program to calculate the power using recursion.| c programming

 program to calculate the number by entering the base and power of a number by recursive function 

In this program, we are will now calculating the  power of the number by taking input base and power of the number by the user 

if the exponent is 0 ,then power is 1. this is the base condition of our recursive function. 

In this program ,the function fun() is recursive function. if the power of the number is zero ,then the function return 1.

if the power not 0 then , the function recursively call itself .

#include<stdio.h>
#include<conio.h>
void main()
{
   int b,p;
   printf("enter the base of the number\n");
   scanf("%d",&b);
   printf("enter the power of the number\n");
   scanf("%d",&p);
   printf("the number is %d",fun(b,p));
   getch();
}
int fun(int a,int b)
{
   if(b!=0)
         return(a*fun(a,b-1));
   else
         return(1);
}

output:
     






















c-program to print the reverse of the number .| c-programming languages

 program to reverse the number in c-programming.

In this program, we will reverse the number by taking the input from the user .

If the number is entered by the user is 234 then the revere of the number is 432.


#include<stdio.h>
#include<conio.h>
void main()
{
   int x,y,rev=0;
   printf("enter the number\n");
   scanf("%d",&x);
   while(x!=0){
         y=x%10;
         rev=10*rev+y;
         x=x/10;
   }
   printf("the reverse of the number is %d",rev);
   getch();
}

output:

         enter the number 457
       the reverse of the number is 754



Monday, 12 April 2021

c-program to calculate the sum of the digits of the numbers using recursion.| c-programming

Q.no program to calculate the sum of the digits of the number using recursion in c-programming. 

In this program, we will calculate the sum of the digits of the number by taking the input from the user in c-programming

recursion means function calling itself is called recursion .

#include<stdio.h>
#include<conio.h>
int sum(int n);
void main()
{
   int n;
   printf("enter the number\n");
   scanf("%d",&n);
   printf("the sum of the digits of the number is %d",sum(n));
   getch();
}
int sum(int n)
{
   if(n/10==0)
         return(n);
   else
         return(n%10+sum(n/10));
}


Output:-
               enter the number 343
                sum of the digits of the number is 10.

For more c-programming example:-











c-program calculate the hcf and lcm of two numbers| c-programming languages

program calculate the hcf and lcm of two number in c-programming.

In this program , we will calculate the hcf and lcm of two numbers in c-program taking two inputs from the user .

 In this program, we first calculate the hcf and with the hcf calculate the lcm of two numbers.

 

#include<Stdio.h>
#include<conio.h>
void main()
{
    int a,b,h,l,i,lcm;
    printf("enter the two number ");
    scanf("%d %d",&a,&b);
    l=a<b?a:b;
    for(i=l;i>=1;i--)
        if(a%i==0&&b%i==0)
         break;
    printf("the hcf of the number is %d",i);
    lcm=(a*b)/i;
    printf("\nhe lcm of the number is %d",lcm);
    getch();
}

output:
              enters two numbers:
               a=12  and b=16
               hcf=4        and   lcm=48



c-program to check weather the year is leap year or not | c-programming questions

 program to check  leap year or not in c-programming.

In this program, user will enter the values and  check weather the year is leap year  or not .

It is not true to say that If a year is divisible by 4 then it is a leap year and it is not divisible by 4 then it is not a leap year. 
 A year is a leap year if and only if :-
 .It  is first divisible by 100 ,then it should  also be  divisible by 400.
. except this , if the year is divisible by is  4 then it is leap year.

lets us write this logic in c-program. To understand this program in c-programming.


 #include<stdio.h>
#include<conio.h>
void main()
{
   int year;
   printf("enter the number\n");
   scanf("%d",&year);
   if(year%100==0){
         if(year%400==0)
                  printf("leap year");
         else
                  printf("not a leap year");
   }
   else{
         if(year%4==0)
                  printf("leap year");
         else
                  printf("not a leap year");
   }
   getch();
}


output: 

                 enter the values of the year a= 200

                     200 is a leap year.


For more c-programming :-









c-program to calculate the lcm of two numbers | c-programming languages

 Q.no program to calculate the lcm of two number in c-programming.

In this program, we will calculate the lcm (least common multiple ) of two numbers by taking input form the user  in c -programming.


The lcm of two integer a and b is the smallest positive integer that exactly divisible by both the number
(without any remainder), 


#include<stdio.h>
#include<conio.h>
 main()
 {
     int a,b,l;
     printf("enter the two  numbers\n ");
     scanf("%d %d",&a,&b);
     for(l=a>b?a:b;l<=a*b;l++)
     {
         if(l%a==0&&l%b==0)
         {
             printf("the lcm of the two number is %d",l);
             break;
         }
     }
     getch();
 }

 output:      enter the two numbers a=12  and b=16
     
                  the lcm of the two numbers is 48.

c-program to calculate the HCF of two numbers. | c-programming languages

 Q.no write a program to calculate the HCF of two number in c-programming

In this program, we are now calculate the HCF or GCD of two number by taking input from the user.

HCF is also known as GCD (greatest common divisor).

The HCF and GCD of two number is the largest integer that can exactly divide both the numbers i.e the highest common factor of two values .


#include<Stdio.h>
#include<conio.h>
main()
{
    int a,b,i;
    printf("enter the number ");
    scanf("%d %d",&a,&b);
    for(i=a<b?a:b;i>=1;i--)
        if(a%i==0&&b%i==0)
        {
            printf("hcf of the number is %d",i);
            break;
        }
    getch();
}

output: 
             
enter the two numbers a=12 and b=16
                the hcf  of the numbers are 4.



Sunday, 11 April 2021

c-program to find the GCD of two numbers by recursion | c-programming languages

 program two find the GCD of the two number using recursion  in c-programming 




In this program, we will now calculate the GCD(greatest common divisor) of two number using recursion   in c-programming and takes two  positive number  from the user 






#include<stdio.h>
#include<conio.h>
int hcf(int n1,int n2);
void main()
{
   int n1,n2;
   printf("enter the two numbers\n");
   scanf("%d %d",&n1,&n2);
   printf("G.C.D of %d and %d is %d",n1,n2,hcf(n1,n2));
   getch();
}
int hcf(int n1,int n2)
{
    if(n2!=0)
         return hcf(n2,n1%n2);
    else
         return n1;
}































  output:-

               enter the number n1=12 and n2=16

                        GCD is 4 





For more c-programing examples:-


. fibonacci series using recursion in c-programming

 


c-program to find the sum of the natural number by recursion


.

c-program to calculate the factorial of the number by recursion


.

c-program to sum of the digits of the number in recursion


.




c-program to find the sum of the natural number by recursion. | c-programming languages

program to calculate the sum of  the natural number by using recursion.

In this program we ,we now calculate the sum of natural number using recursion in c-program, taking  input  positive integer from the user.
Recursion means function calling itself is called recursion.
suppose 15 is passed as an argument  to the function fun() ,from the main method . In the fun() function,
subsequently until "if" statement  returns the false value ,then the value decrease by one in every step and   we added fun(num-1) to num. the statement is doing it until num value is 0. if the num values is 0 ,then the else block gets execute and o is return
Therefore ,function return the value form which where function is call in the main()function.

#include<stdio.h>
#include<stdio.h>
int fun(int num);
void main()
{
   int n,sum=0;
   printf("enter the number\n");
   scanf("%d",&n);
   sum=fun(n);
   printf("the sum of the number is %d",sum);
   getch();
}
int fun(int num)
{
   if(num==1)
         return(1);
   else
         return(num+fun(num-1));
}

Output:- enter the number:- 15
           the sum of the number is 120.

For more c-programming example:-

1.c-program to calculate the sum of the natural number by using recursion







program to calculate the factorial of the number by recursion in c-language.| c-programming

 program to calculate the factorial of the number by recursion in c-language. 


In this program, we will learn to find the factorial of the natural number by using  recursion and user entered the value.
we will use a recursive user defined function to perform the task .
The factorial of a negative number doesn't exit .
The factorial of 0 is 1.
recursion mean function calling itself . 

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

output

  enter the number :  5

   factorial of 5 is 120



For more c-programming example:

1.c-program to calculate the GCD of two number by recusion

2.c-program to display fibonacci series by using recusion

3.c-program to calculate the sum of the number by using recursion







c-program to print the ASCII symbol in c-language

 program to print the ASCII symbol in c-language

In this program, we will  now print the all the ASCII values in c-programming.

In c-programing language, their are 256 ASCII character or ASCII values i,e form 0 to 256.
 for example , the ascii value of 'A' is 65. and the ascii value of 'a' is 97.


/* print all the ascii code */
#include<stdio.h>
#include<conio.h>
void main()
{
    char ch;
    int i;
    for(i=0;i<=256;i++){
       printf("%d %c\n ",i,ch);
       ch=ch+1;
    }
    getch();
}