how to upgrade to windows 10 from windows 8.1

If you want to upgrade to windows 10 from windows 8.1 then follow* this procedure.

step1 : make sure you have installed all updates from windows. This is done as follows.
           control panel > search for update in control panel search box > click on windows update > check for updates > if there are any updates, install them. once again make sure, you have installed all updates asa same as above.

step2 : download file from
step 3: run the file
step 4 : click on upgrade this pc.
now the download should start. 
if you got error like "something happened", then do the following
 open control panel > search for region > click on region > click on administrative > chane local> put english(united states) in that and click ok
now run that downloaded file again.
your download should start now.
be patient ... you need to do nothing until it gets downloaded 100%
then some processes start by themselves.
be patient..
in the entire process, it asks your permission thrice only.
You got windows 10 on your PC.
All the best.

If you have some issue/solution, Feel free to share here.

*this is for information only. There is no guarantee that it will work for u.

Simple calculator

Problem Statement: Execute simple arithmetic operations sum, subtract, multiplication, division on integers.

How its different from others on internet :  There are so many websites which have code for simple calculator program. However most of them, asks for two integers first and then asks for operator which is not the case in real time calculator. In this code, you can directly enter expressions like        76 * 75, which is similar to real time calculator.

Input : operand1 operator operand2
Output : result of the input arithmetic expression.

Code:

#include <stdio.h>
#include <string.h>

float calculate(int op1, char op, int op2, unsigned short * flagptr); // calculator function
int main()
{
 char oparr1[10], oparr2[10];
 char op;
 float result;
 unsigned short flag = 1;   // flag which indicates any error in input
 unsigned short *flagptr = &flag; // pointer to the above flag
 printf("enter expression operand1 operator operand2\n");
 int ch;
 ch = getchar();  // start reading input
 int i= 0;
 while(ch >= '0' && ch <= '9')   //store in array of operand1 if its number
 {
    oparr1[i] = ch;
    ch = getchar();
    i++;
 }
 while(ch == ' ')       // skip all the spaces between first operand and operator, if any
 {
    ch = getchar();
 }
 op = ch;      // store operator in op
 ch = getchar(); 
 while(ch == ' ')
 {
    ch = getchar();
 }
 i= 0;
 while(ch >= '0' && ch <= '9')      //start reading operand2
 {
    oparr2[i] = ch;
    ch = getchar();
    i++;
 }
 int op1, op2;
 op1 = atoi(oparr1);     // convert char array of operand1 to integer
 op2 = atoi(oparr2);
 result = calculate(op1, op, op2, flagptr);
 if (flag == 1)              // no error in input
    printf("result = %f\n", result);
 else
    printf("undefined result\n");
 return 0;
}

float calculate(int op1, char op, int op2, unsigned short *flagptr)
{
    float result;
    switch(op)
    {
        case '+': result = op1 + op2;
                break;
        case '-': result = op1 - op2;
                break;
        case '*': result = op1 * op2;
                break;
        case '/':
                if (op2 != 0)
                    result = (float)op1/op2;
                else
                    {
                       printf("divide by zero error\n");
                       *flagptr = 0;   // indicate error in input
                    }

                break;
        default : printf("Use integers only\nUse +, -, * and / only\n");
                     *flagptr = 0;
                      break;

    }
    return result;
}
 



Sample input: 25 * 25
Output : 625.00000

What can be improved? 
Ans: Well, this program works only for integers. Try for floating point values and use it as your own calculator. Discuss in comments, how to implement it for float values.

Quiz-7


What is the output of the following code:

#include<stdio.h>
int main()
{
        int i=5;
        while(i<10)
        {
              printf("%d ",i);
              if(i==7)
              {
                   while(1)
                   {
                         printf("K ");
                         i++;
                         if(i==9)
                            break;
                   }
              }
              else printf("%d ",++i);
        }
        return 0;
}

Choices:

1) Compile error or execution stops.
2) 5 6 6 7 K K 9
3) 5 6 6 7 7 K K 9
4) 5 6 6 7  7 K K 9 10
5)None of the above(If your choice is 5, then provide your answer and explanation).
 
Answer is posted on our Facebook fan page  here 

Insertion sort

Program:

/***  insertion sort function   ***/
#include<stdio.h>
void insertionsort(int a[],int size);
#define MAX 10
int main()
{
         int a[MAX];
         int i;
         printf("enter %d elements:: ",MAX);
         for(i=0;i<MAX;i++)                     /** read the numbers to be sorted  **/
         scanf("%d",a+i);
         int length=MAX;
         insertionsort(a,length);              /**   function call  **/
         for(i=0;i<MAX;i++)                   /** print numbers in non-decreasing order **/
         printf("%d ",*(a+i));
         return 0;
}
void insertionsort(int a[],int size)
{
         int i,j,key;
         for(i=1;i<size;i++)
         {
                key=a[i];
                j=i-1;
               while((key<a[j])&&(j>=0))
               {
                     a[j+1]=a[j];
                     a[j]=key;
                      j--;
                }
          }
          return;
}
 

Sample input:

1 4 6 5 2 3 7 4 8 9

Output:

1 2 3 4 4 5 6 7 8 9
 
Algorithm:
 
for i=1 to length of array
                key=a[I]
                j=i-1
               while(key<a[j])AND(j>=0)
                     a[j+1]=a[j]
                     a[j]=key
                      j--
return array.

Quiz-6

Choose one of the following choices in relevance to the output of the following code.

#include<stdio.h>
int main()
{
      int a[20];
      int i=15;
      printf("a[%d]=",i++);
      printf("%d",++i);
      return 0;
}

1) Compile error (or) execution stops.
2) a[15]=17
3) a[16]=17
4) a[16]=16
5) a[15]=16
6) None of the above.

For Answer and Explanation visit our Facebook fan page here
 

Quiz5

Choose one of the choices given below.

#include<stdio.h>
int main()
{
   printf("%d%d",printf("hai"), printf("hello"));
   return 0;
}

Quiz 4

Choose one, among the given choices according to the output of the following code.
Code:
/* code to check collinear points(?)    */
#include<stdio.h>
int main()
{
      int a,b,c,d,e,f;
      a=1;b=1;c=1;d=2;e=1;f=3;
      if(((d-b)/(c-a))==((f-d)/(e-c)))
      printf("collinear points");
      else printf("Not");
      return 0;
}

Choices:

1) Compile error.
2) Compiles but stops execution.
3) Not
4) collinear points
5) None of the above.

Answer, explanation and trick(if any) for the above will be given on our Facebook page
                                                         visit Facebook page

Recursion example-3 (medium):: Length of longest contiguous increasing subsequence

Length of longest contiguous increasing subsequence.


Program:

#include<stdio.h>
int len_longseq(int, int, int);              /* function prototype  */
int max=-1;                                      /* declare max variable globally   */
int main()
{
       int n,prev;  
       printf("enter number of numbers");
       scanf("%d",&n);              
       if(n>0)
       {                                                      /* if n>0 proceed  */
             scanf("%d",&prev);                 /* read first integer  */
             int count=1;                       /* initialize count to 1  */
             if(n==1)                           /* if n=1 then print count=1 and stop  */
             printf("%d",count);
             else
            {                                                     /* if n>1   */
                    count=len_longseq(prev,n-1,1);          /* function call  */
                    printf("%d",count);                             /* print output  */
             }
        }          
        return 0;
}
int len_longseq(int prev,int n,int count)      /* function definition  */
{
    if(max<count)                                  /* to keep the length of longest subsequence so far */
           max=count;
    if(n==0)                                     /* base case if n=0,return max and stop  */
          return max;
    int x;
   scanf("%d",&x);                              /* read next number  */
   if(x>prev)                                   /* if read value is greater than previous read value  */
          return(len_longseq(x,n-1,++count));
 
   return (len_longseq(x,n-1, 1));               /* if read value is not greater than previous read value  */
}

Sample input:

enter number of numbers: 7
5  6  7  8  9  1  2

Output: 5

Recursion example-2 (easy)


Product of n numbers read from the input.

Program:

#include<stdio.h>
int read_mul(int);                                       /*  function prototype   */
int main()
{
       int n;
       printf("enter number of numbers");
       scanf("%d",&n);                                  /* read number of numbers  */
       printf("%d",read_mul(n));                   /* print product   */
       return 0;
}
int read_mul(int n)                                      /* function definition  */
{
       if(n==0)                                  /* base case i.e., if n=0 stop recursion and return 1 */
       return 1;
       int x;                                                     /* if n is not zero read and evaluate product  */
       scanf("%d",&x);
       return x*read_mul(n-1);                      /*  recursive function call   */

}

Sample input:

5
1 2 3 4 5

Output:
120

Recursion example-1(easy)


Sum of n numbers read from the input.

Program:

#include<stdio.h>
int read_sum(int);                                       /*  function prototype   */
int main()
{
       int n;
       printf("enter number of numbers");
       scanf("%d",&n);                                  /* read number of numbers  */
       printf("%d",read_sum(n));                   /* print sum   */
       return 0;
}
int read_sum(int n)                                      /* function definition  */
{
       if(n==0)                                  /* base case i.e., if n=0 stop recursion and return 0 */
       return 0;
       int x;                                                     /* if n is not zero read and evaluate sum  */
       scanf("%d",&x);
       return x+read_sum(n-1);                      /*  recursive function call   */

}

Sample input:

5
1 2 3 4 5

Output:
15

I Love You program in c




Program:                                                                  like us on facebook 

#include<stdio.h>
int main()
{
       char ch;
       char a[20][20];                  /*   2D array declaration   */
       printf("enter i or I");
       scanf(" %c",&ch);              /*  read input     */
       printf("\n\n\n");                  /* for new lines (optional)   */
       int i,j,k;
       switch(ch)
       {
             case 'I':
             case 'i':
                            for(i=0;i<8;i++){             /*   for every row   */
                            if(i==0||i==7){                 /* if row is either 1st or last   */
                            for(j=0;j<11;j++)             /* for every column   */
                            printf("\x03");                  /* print love symbol   */
                            printf("\n");
                             }
                            else{                                 /* if row is neither 1st nor last   */
                            printf("     \x03\n");
                            }
                            }
                            printf("\n\n\n");                /* after printing I, new lines   */

            case 'L':   for(i=0;i<10;i++)              /* 1st store love symbol in all element spaces  */
                           {
                                for(j=0;j<12;j++){
                                a[i][j]='\x03';
                                }
                           }
                          for(i=0;i<2;i++)          /* replace some of the above symbols with white spaces */
                         a[i][5]=' ';                     /* top space   */
                         for(i=2;i<10;i++)         /* left spaces   */
                         {
                               for(j=0;j<i-1;j++)
                               a[i][j]=' ';
                        }
                        for(i=2;i<10;i++){       /* right spaces   */
  
                            for(j=10;j>11-i;j--)
                            a[i][j]=' ';
                        }
                        for(i=0;i<10;i++){          /*  print */
                            for(j=0;j<11;j++)
                            printf("%c",a[i][j]);
                            printf("\n");
                        }
 case 'U':          for(i=0;i<8;i++){                      /* for every row   */
                         if(i!=7)                                      /* if its not last row   */
                               printf("\x03         \x03");
                        else{                                             /*   if its last row   */
                              for(j=0;j<11;j++)
                              printf("\x03");
                              }
                       printf("\n");
                       }
    
         }
 
 return 0;
 }
 
Note: Purposefully I have not put break statements and default statement in the switch for user friendly. You can add them at appropriate places.
 
Input:  Give input i or I.
 

quiz 3

Output of the following?

#include<stdio.h>
int main()
{
   int a,b,c,d,e,f;
   a=1;b=4;c=2;d=3;e=5;f=3;
   printf("%d",1-a+b*c%d/(e-f));
   return 0;
}

Choices:

a) compile error     b) execution stops     c) 0     d). 1     e) -3      f) 2    g)none
For explanation visit "click here for program" link below.



step.1: 1-a+b*c%d/(5-3)     ( brackets have highest priority among all)
step.2: 1-a+b*c%d/2
step.3: 1-a+4*2%d/2          ( *,/,% have same priority and have left to right associativity )
step.4: 1-a+8%3/2
step.5: 1-a+2/2
step.6: 1-a+1
step.7: 1-1+1                     ( +, - have same priority and have left to right associativity)
step.8: 0+1
step.9: 1
Now the expression returns its result. so 1 is printed
 
Don't want to miss updates from us!! follow us or subscribe to us.

C program to convert the given decimal number to its binary equivalent.

 


Program:

/* c program to convert the given decimal number into its binary equivalent. */
#include<stdio.h>
#define SIZE 80
struct stack{                      /*   defining a structure for stack    */
    int line[SIZE];
 int top;                       /* top index of stack  */
 };
void push(struct stack*, int);
int pop(struct stack*);
int main()
{
        struct stack s;  
        s.top=-1;                /* initializing  empty stack i.e, top index=-1 */
        int num;
        int rem,temp;
        printf("Decimal number to be converted: ");
        scanf("%d",&num);
        if(num==0)
            printf("%d",num);
        while(num>0)  /* while num>0, divide the number by 2 and store the remainder in stack  */
        {
               rem=num%2;
               push(&s,rem);
               num=num/2; 
        }
        printf("Binary number: ");
        while(s.top!=-1)        /* while stack is not empty */
        {
               temp=pop(&s);
               printf("%d ",temp);
        }
         return 0;
}
void push(struct stack *ps, int x)      /* function to push, ps is pointer to stack */
{
       if((ps->top)==SIZE-1)                /* if no more element can be accommodated */
      {
              printf("stack overflow");
              return;
      }
      int a=++(ps->top);                   /* increment top index   */
      ps->line[a]=x;                       /* push the element onto stack */
      return;
}
int pop(struct stack* ps)
{
       if(ps->top==-1)                        /* if stack is empty */
      {
             printf("stack underflow");
             return;
      }
      int x=(ps->line[(ps->top)]);           /* pop the value from the top of stack */
      (ps->top)--;                           /* decrement top index of stack   */
      return x;
}

Sample input and output:

Decimal number to be converted: 100
Binary number: 1 1 0 0 1 0 0
 
Now you can do some changes in the code to write the code for decimal to octal conversion.

C program to find out if a solved Sudoku is valid or invalid.


Object of this program is to find out if a solved Sudoku is valid or invalid.

/* when the program encounters "break;" statement, execution will come out of the innermost loop in which it present. */

Program:

#include<stdio.h>
int main()
{
         int a[9][9];
         int i,j,sum,temp,flag=1;
         printf("\n enter input::\n");
         for(i=0;i<9;i++){
             for(j=0;j<9;j++){
                  scanf("%d",&temp);
                  if(temp>0 && temp<10)          /*   check for valid input for Sudoku   */
                  a[i][j]=temp;
                  else{                               /* if any element is not invalid then successive breaks  */
                        flag=0;                             
                        printf(" invalid input ");
                        break;
                      }
             }
             if(flag==0)
             break;
         }
          if(flag)             /* if every input is in valid range then go for validation of Sudoku  */
         {
               for(i=0;i<9;i++)
               {
                    sum=0;
                    for(j=0;j<9;j++)
                    sum=sum+a[i][j];
                    if(sum!=45)
                       break;            /*   if sum is not 45 in any row then  go out of for loop  */
               }
               if(sum==45)                /*  if sum is 45 in all rows then check for columns   */
               {
                     for(i=0;i<9;i++)
                    {
                          sum=0;
                          for(j=0;j<9;j++)
                          sum=sum+a[j][i];
                          if(sum!=45)           
                          break;        /*   if sum is not 45 in any column then  go out of for loop  */
                    }
                    if(sum==45)                              /* if sum is 45 in all columns too    */
                       printf("Valid");
                    else printf("invalid");
               }
               else
                   printf("\n Invalid");
         }
         return 0;
}


Sample input:

1 9 4 8 7 5 6 2 3
8 5 3 9 6 2 4 7 1
2 6 7 3 1 4 9 8 5
9 2 1 6 5 8 7 3 4
6 7 8 4 3 1 2 5 9
4 3 5 2 9 7 8 1 6
5 8 6 7 4 3 1 9 2
3 4 2 1 8 9 5 6 7
7 1 9 5 2 6 3 4 8

Output:

Valid
 

Read into the computer a line of text containing both uppercase and lowercase letters. Printout the text with the uppercase and lowercase letters reversed, but all other characters intact.

Sample input:

I Love Programming.

Output:

i lOVE pROGRAMMING.

 Program:

/* c program to convert the upper case text to lower case text and vice versa    */
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
       char line[80];
       printf("enter some text: ");
       scanf(" %[^\n]",line);
       int len= strlen(line);
       int I;
       for(i=0;i<len;i++)
       {
                if(line[i]>='a' && line[i]<='z')
                        line[i]=toupper(line[i]);
                else if(line[i]>='A' && line[i]<='Z')
                        line[i]=tolower(line[i]);
        }
        printf("%s",line);
        return 0;
}

Note: Here the tests for lowercase and uppercase are not necessary. Think and comment if you need any help

quiz 2

What is the output of the following program? Read the choices before answering.

#include<stdio.h>
int main()
{
         int  a,b;
         printf(enter a,b: );
         scanf("%d%d",&a,b);
         printf("%d  %d",a,b);
         return 0;
}

Input:

4   5

choices:


1. compile error
2. compilation success, but program stops when run
3. 4   5
4. strange output
5. None of the above
 

quiz on printf()

what is the output of the following code?

#include<stdio.h>
int main()
{
         int a,b,c;
         a=1;
         b=1;c=2;
         printf("%d %d %d %d",a,b,c);
         return 0;
}

choose one answer among the following.

1. compile error
2. compiled, but stops when run
3. 1 1 2
4.strange output
5. None

Print the intermediate values between two successive elements. Let n=4, and array elements are 4, 2, 7, 5. The output would be ( 2 3 4 ) ( 2 3 4 5 6 7 ) ( 5 6 7 )


Program:

#include<stdio.h>
int main()
{
       int n;
       int i, j;
       printf("n: ");
       scanf("%d",&n);
       int a[n];
       printf("enter elements\n");
       for(i=0;i<n;i++)
       scanf("%d",&a[i]);
       for(i=0;i<n-1;i++)
       {
                 printf("( ");
                 if(a[i+1]>a[i])
                {
                        for(j=a[i];j<=a[i+1];j++)
                        printf("%d ",j);
                 }
                 else if(a[i+1]<a[i])
                 {
                       for(j=a[i+1];j<=a[i];j++)
                       printf("%d ",j);
                 }
                 else printf("%d %d ",a[i],a[i]);
                 printf(") ");
        }
        return 0;
}

How many times does each element occur in the given array? Let n=7, and the elements are: 12, 34, 32, 12, 36, 32, 32. The output should be: (12: 2); (34: 1); (32: 3); (36,1) but should not be (12: 2); (34: 1); (32: 3); (12: 2); (36: 1); (32: 3); (32: 3).


Program:

#include<stdio.h>
#define undefined 10000    /* take a value which is beyond the range of values in the program */
int main()
{
       int n;
       int i, j,count;
       printf("n: ");
       scanf("%d",&n);
       int a[n];
       printf("enter elements\n");
       for(i=0;i<n;i++)
       scanf("%d",&a[i]);
       for(i=0;i<n;i++)
      {
             count=1;
             if(a[i]!=undefined)
            for(j=i+1;j<n;j++)
            {
                  if(a[i]==a[j])
                  {
                         count++;
                         a[j]=undefined;
                   }
            }
            if(a[i]!=undefined)
            printf("(%d,%d); ",a[i],count);
     }
     return 0;
}

Point of intersection of two lines

Write a program that reads a, b, c, p, q and r. Let ax + by + c = 0 and px + qy + r = 0 be the equations
of two lines. Print their point of intersection.

Program:

#include<stdio.h>
int main()
{
      int a,b,c;
      int p,q,r;
      printf("a,b,c: ");
      scanf("%d%d%d",&a,&b,&c);
      printf("p,q,r: ");
      scanf("%d%d%d",&p,&q,&r);
      int x,y;
      x=(b*r-q*c)/(a*q-b*p);
      y=(p*c-a*r)/(a*q-b*p);
      printf("point of intersection (x,y)=(%d,%d)",x,y);
      return 0;
}

Sample input:

a,b,c: 4 8 12
p,q,r: 2 7 3
Sample output:
point of intersection (x,y)=(-5,1)



expand the given string if it contains a range

Objective of this program is to expand the given string if it
contains a range, for example a-f, 0-5. 

Following are considered valid range expressions: 
1. lower case letters between a and z.  Ex: a-f, d-i
2. Upper case letters between A and Z.  Ex: A-F, D-I
3. Numbers between 0 and 9. Ex: 1-5
4. All the above 3 in the reverse order. Ex: f-a, F-A, 3-0

In case of invalid sequences in the input string, sequence
should be copied as is. 

--------------------------------------
Sample Input       Sample Output
--------------------------------------
a-fuy0-3ZA-F       abcdefuy0123ZABCDEF
a-f6-3F-9          abcdef6543F-9
-ABCD-             -ABCD-
-------------------------------------



Program:
#include<stdio.h>
int main()
{
       int l,m,n,f,g;
       char a[1000];
       int i;
       int j;
       scanf("%s",a);
       int valid,validr;
       i=0;
       while(a[i]!='\0')
      {
              printf("%c",a[i]);
              i++;
             while((a[i]!='-')&&(a[i]!='\0'))
             {
                    printf("%c",a[i]);
                    i++;
             }
             if(a[i]!='\0')
            {
                   f=i-1;g=i+1;
                   valid=0;validr=0;
                   if(a[f]>='A' && ((a[g]>='A')&&(a[g]>=a[f])))
                   valid=1;
                   else if((a[f]>='a' && ((a[g]>='a')&&(a[g]>=a[f]))))
                   valid=1;
                   else if(a[f]>='0' && ((a[g]>='0')&&(a[g]>=a[f])))
                   valid=1;

                   else if((a[g]>='A' && ((a[f]>='A')&&(a[f]<=a[g]))))
                   validr=1;
                   else if((a[g]>='a' && ((a[f]>='a')&&(a[f]<=a[g]))))
                   validr=1;
                   else if((a[g]>='0' && ((a[f]<='9')&&(a[f]>=a[g]))))
                   validr=1;
                   if(valid)
                   {
                          for(j=a[i-1]+1;j<a[i+1];j++)
                          printf("%c",j);
                          i++;
                  }
                  else if(validr)
                 {
                         for(j=a[i-1]-1;j>a[i+1];j--)
                         printf("%c",j);
                         i++;
                 }
 
           }
           else break;
       }
       return 0;

equilateral triangle of stars.

 C program to print the equilateral triangle of stars

sample input and output:
 
 
 
 
 
 
 
 
 


Program:
 
#include<stdio.h>
int main()
{
    int height_pyramid;
    do
    {
        printf("how much height do tou want to print: ");
        scanf("%d",&height_pyramid);
    }while (height_pyramid < 1 || height_pyramid > 23);
    int i,j,k,n;
    n=height_pyramid;
    for (i=1, j=n; i<=j; i++,n--)
    {
        for(k=0;k<n-1;k++)
            printf(" ");
        for(k=0;k<i;k++)
            printf("* ");
        printf("\n");
    }
    return 0;
}


convert keyboard inputted seconds into days, hours, minutes and seconds



C program to convert keyboard inputted seconds into days, hours, minutes and seconds.

Program:
 
#include<stdio.h>
int main()
{
       int sec;
       int min,hrs,days,temp;
       printf("Total seconds: ");
       scanf("%d",&sec);
       days=(sec/86400);
       temp= sec%86400;
       hrs=temp/3600;
       temp=temp%3600;
       min=temp/60;
       sec=temp%60;
       printf("days: %d\t hours: %d\t minutes: %d\t seconds: %d",days,hrs,min,sec);
       return 0;
}

Sample input:

Total seconds: 86462

Output:

days: 1         hours: 0          minutes: 1           seconds: 2

Series of numbers

 

A series of numbers is as follows:
1, 1, 1, 3, 5, 9, 17, 31, 57, 105, . . . , An = An-1 + An-2 + An-3
Write a Computer Program to compute An for the user input n, where A1 = A2 = A3 = 1.

Program:

#include<stdio.h>
int main()
{
             int num;
             int A1=1,A2=1,A3=1;                 /* initialize to start the series */
             int A4,i;
             printf("enter num: ");
             scanf("%d",&num);
             for(i=4;i<=num;i++)                      /* starting from 4th term  */
            {
                       A4=A1+A2+A3;                 /* next term in the series */
                       A1=A2;
                       A2=A3;
                       A3=A4;
             }
             printf("%dth number in the series= %d",num,A4);
             return 0;
}

Sample input:

 enter num: 10

Output:

10th number in the series= 105

combinations of I, J, K and L, such that :I + J + K = L and I < J < K < L. I, J, K and L be positive integers from 1 to 15



Let I, J, K and L be positive integers from 1 to 15. Write a program that finds and prints all
combinations of I, J, K and L, such that :
                                                           I + J + K = L and I < J < K < L.

Program:

#include<stdio.h>
int main()
{
      int i,j,k,l;
      for(l=1;l<=15;l++)
      for(k=1;k<l;k++)
      for(j=1;j<k;j++)
      for(i=1;i<j;i++)
      {
            if((i+j+k)==l)
            printf("%d+%d+%d=%d \n",i,j,k,l);
       }
       return 0;
}

Output:

1+2+3=6
1+2+4=7
1+3+4=8
1+2+5=8
2+3+4=9
1+3+5=9
1+2+6=9
2+3+5=10
1+4+5=10
1+3+6=10
1+2+7=10
2+4+5=11
2+3+6=11
1+4+6=11
1+3+7=11
1+2+8=11
3+4+5=12
2+4+6=12
1+5+6=12
2+3+7=12
1+4+7=12
1+3+8=12
1+2+9=12
3+4+6=13
2+5+6=13
2+4+7=13
1+5+7=13
2+3+8=13
1+4+8=13
1+3+9=13
1+2+10=13
3+5+6=14
3+4+7=14
2+5+7=14
1+6+7=14
2+4+8=14
1+5+8=14
2+3+9=14
1+4+9=14
1+3+10=14
1+2+11=14
4+5+6=15
3+5+7=15
2+6+7=15
3+4+8=15
2+5+8=15
1+6+8=15
2+4+9=15
1+5+9=15
2+3+10=15
1+4+10=15
1+3+11=15
1+2+12=15
 

Interchange the last two digits of an inputted number


C program to interchange the last two digits of an inputted number.

Sample input:
12369

Output:
12396

Program:

#include<stdio.h>
int main()
{
         int num,temp1,temp2;
         printf("enter num: ");
         scanf("%d",&num);
         temp1=num%10;
         temp2=num/10;
         temp2=temp2%10;
         num=num-(10*temp2)+(10*temp1)-(temp1)+(temp2);
         printf("%d",num);
         return 0;
}
 

Delete the second last digit of an inputted number


C program to delete the second last digit.

Sample Input 12345, Output 1235
 

Program:

#include<stdio.h>
int main()
{
        int num,temp1,temp2;
        printf("enter num: ");
        scanf("%d",&num);
        temp1=num%10;                  /* store last digit in temp1   */
        num=num/10;                       /* making number one digit shorter   */
        temp2=num%10;                  /* store the second last digit in temp2   */
        num=num-temp2+temp1; /* add the last digit and subtract second last digit to shorter number  */
          printf("%d",num);
          return 0;
}

Double the last digit of an inputted number


 c program to double the last digit of an inputted number. Example: Input 72564, Output 72568
(Assume that the last digit is less than 5)

Program:

#include<stdio.h>
int main()
{
          int num,temp;
          printf("enter num: ");
          scanf("%d",&num);
          temp=num%10;
          if(temp<5)
          {
                  num=num+temp;
                  printf("%d",num);
          }
          else
          printf("enter number such that its last digit is less than 5.");
          return 0;
}

Input:

12454

Output:

12458

 

g(x, y) = f(x) + f3(y)

#include<stdio.h>
#include<math.h>
int f(int, int, int);                                  /* function prototype for f(x)   */
int main()
{
          int a,b;
          int x,y;
          double g;                                           /*       g=g(x,y)         */
          printf("a, b: ");
          scanf("%d%d",&a, &b);
          printf("x,y: ");
          scanf("%d%d",&x, &y);
          g=(f(x,a,b))+(pow((f(y,a,b)),3));             /* make sure that return value of pow()
                                                                                                      function is assigned to double  */
          printf("g(%d,%d)=%g",x,y,g);
          return 0;
}
int f(int x, int a, int b)
{
         return(a*x+b);
}

Sample input:

a, b: 5 6
x, y: 2 6

Output:

g(2,6)=46672