C PROGRAMMING LANGUAGE @

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Saturday, July 15, 2017

Write a code Find the sum of odd numbers and sum of even numbers in a given range

July 15, 2017
Write a code Find the sum of odd numbers and sum of even numbers in a given range

//Write a code Find the sum of odd numbers and sum of even numbers in a given range

                                                                     

Algorithm:
procedure()
sum=0;
for i=1 to n;
sum=sum+(i*i*i);
end procedure;
source code:
#include<stdio.h>
int main()
{
int i,n,sum=0,sum1=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 5
for(i=1;i<=n;i++)
{
if(i%2==0)
{
sum=sum+i;
}
else
sum1=sum1+i;
}
printf("Sum of even number is %d.\n",sum);
printf("Sum of odd number is %d.\n",sum1);
}
output:
Sum of even number is 6
Sum of odd number is 9
                                                                       




Read More

Saturday, July 8, 2017

Write a code to get the summation of the n^3 series

July 08, 2017
Write a code to get the summation of the n^3 series

Write a code to get the summation of the following series: 1^3 + 2^3 + 3^3 + 4^3 + ………… + n^3 terms.

                                                                 
c programming problem and solution
Algorithm:
procedure()
sum=0;
for i=1 to n;
sum=sum+(i*i*i);
end procedure;
source code:
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 5
for(i=1;i<=n;i++)
{
sum=sum+(i*i*i);
}
printf("Sum is %d.\n",sum);
return 0;
}
output:
sum is 225.                                          
Read More

Friday, July 7, 2017

Write a code to get the summation of the following N series:

July 07, 2017
Write a code to get the summation of the following N series:

Write a code to get the summation of the following series:
1^2 + 2^2 + 3^2 + 4^2 + ………… + n^2 terms.

                                                                 
                                                                     
Algorithm:
procedure()
sum=0;
for i=1 to n;
sum=sum+(i*i);
end procedure;
source code:
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 5
for(i=1;i<=n;i++)
{
sum=sum+(i*i);
}
printf("Sum is %d.\n",sum);
return 0;
}
output:
sum is 55.                                                                              
   
Read More

Thursday, July 6, 2017

Write a code to get the summation of the 'n' series

July 06, 2017
Write a code to get the summation of the 'n' series

Write a code to get the summation of the following series:
1 + 2 + 4 + 7 + ………… + n terms.

                                                                   
Algorithm:
procedure()
sum=0;
for i=0 to n;
sum=sum+((i*i+i+2)/2);
end procedure;

source code:
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 3
for(i=0;i<=n;i++)
{
sum=sum+((i*i+i+2)/2);
}
printf("Sum is %d.\n",sum);
}


output:
sum is 14.
                                                                           

Read More

Thursday, June 15, 2017

one dimensional array c programming language

June 15, 2017
one dimensional array c programming language
More than one item can be given a variable name utilizing only one subscript and such a variable is called a single subscripted variable or a one dimensional [1D] array. 
                                                                                  

In mathematics we usually deal with variables that are single subscripted.  For example we use the equation,
                                                                  
To calculate the average of n values of x. the subscripted variable x refers to the element of x. in  C single  subscripted variable x can be expressed as
X[1],x[2],x[3] …………………………………………………………………………………. x[n]

The subscript can be being with number 0, that is
X[0]

For example, if we want to represent a set of five numbers, say ( 10, 15, 20, 30, 40 ) by an one dimensional array variable number, then we may declare the variable number as follows
number  [0]
number  [1]
number  [2]
number  [3]
number  [4]

The values to the array elements can be assigned as :
number  [0] = 10;
number  [1]  = 15;
number  [2]  =  20;
number  [3]  = 30;
number  [4]  = 40;

This would cause the array (number ) to store the values as shown below :
number  [0]     10
number  [1]     15
number  [2]     20
number  [3]     30
number  [4]     40

these elements may be used in programs just like any other c variable. Such as the following are valid statements:
add = number[0] + 100;
add = number [1] * 100;
add = number [2] / 5;
add = number[3]  –  50;
add = number[1]  +  number [2];
number[5] = number[3]  * number [4];
number[3] = number[5] / number[1];




Read More

Tuesday, June 13, 2017

Write a code to get the summation of the following series: 1 + 3 + 5 + 7 + ………… + 2n-1 terms

June 13, 2017
Write a code to get the summation of the following series: 1 + 3 + 5 + 7 + ………… + 2n-1 terms
 /*Write a code to get the summation of the following series:
1 + 3 + 5 + 7 + ………… + 2n-1 terms */
                                       
Algorithm:
procedure()
sum=0;
for i=1 to n;
sum=sum+2*i-1
end procedure;

source code:
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 10
for(i=1;i<=n;i++)
{
sum=sum+2*i-1;
}
printf("Sum is %d.\n",sum);
}

output:
sum is 100.
 
Read More

Monday, June 12, 2017

find the palindrome using self referential structure

June 12, 2017
find the palindrome using self referential structure
                                                                         
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Node
{
    char data;
    struct Node *next;
} node;



void Append(node **head_ref, char data)
{
    node *new_node;
    new_node=(node *)malloc(sizeof(node));
    node *last;
    last=*head_ref;
    new_node->data=data;
    new_node->next=NULL;

    if(*head_ref==NULL)
    {
        *head_ref=new_node;
        return ;
    }
    else
    {
        while(last->next!=NULL)
        {
            last=last->next;
        }
        last->next=new_node;
        return ;

    }

}

void Reverse(node **temp)
{
    node *current,*prev,*next;
    current=(*temp);
    prev=NULL;
    while(current!=NULL)
    {
        next=current->next;
        current->next=prev;
        prev=current;
        current=next;
    }
    (*temp)=prev;
}

void Compare(node **temp,node **temp1)
{
    node *head,*head2;
    head=(*temp);
    head2= (*temp1);

    while(head->next!=NULL&& head2->next!=NULL&&head->data == head2->data)
    {
        head = head->next;
        head2 = head2->next;

    }
     if(head->next==NULL && head2->next==NULL)
        {
            printf("The word is  palindrome :)");
        }
        else{

             printf("The word is not palindrome");
        }


}


int main()
{
    char user[15];
    printf("Enter the Word: ");
    gets(user);
    node *head=NULL,*head2=NULL;

    int i;
    for(i=0; user[i]!='\0'; i++)
    {
        Append(&head,user[i]);
        Append(&head2,user[i]);
    }


    Reverse(&head2);

    Compare(&head,&head2);


    return 0;
}

output:
                                                                             
Read More