C Programming Examples with Output Part - 1 - Ishwaranand

News

C Programming Examples with Output Part - 1

Program

c program examples, c programming examples with output, basic programs in c, c programs for practice, c language basics, c programs for interview, c programming questions, c programming tutorial, c program examples, basic programs in c, c programming software, c programming tutorial, c programs for practice, c programs with solutions, c program online compiler, c program examples, c program to add two numbers, c program compiler, c program to find factorial of a number, c program to reverse a number, c program to reverse a string, c program for prime number, structure of c program, hello world c program, leap year c program, bubble sort in c program, merge sort in c program, quick sort in c program,
C Programming Examples with Output Part - 1  ~ Image by ©Ishwaranand


1) Write a program to accept two numbers & swap them.

#include <stdio.h>
#include <conio.h>

void main()
{
         int a, b, temp;
         printf("Enter two numbers : ");

         scanf("%d%d", &a, &b);
         printf("\nOriginal values are a = %d b = %d", a, b);

          temp = a;
          a = b;
          b = temp;

          printf("\nAfter exchange a = %d b = %d", a, b);
          getch();
}

Output:
Enter two numbers : 10 20
Original values are a = 10 b = 20
After exchange a = 20 b = 10

2) Write a program to accept two numbers & swap them without an extra (third) variable.

#include <stdio.h>
#include <conio.h>

void main()
{
          int a, b;
          printf("Enter two numbers : ");

          scanf("%d%d", &a, &b);
          printf("\nOriginal values are a = %d b = %d", a, b);

          a = a + b;
          b = a - b;
          a = a - b;

          printf("\nAfter exchange a = %d b = %d", a, b);
          getch();
}

Output:
Enter two numbers : 10 20
Original values are a = 10 b = 20
After exchange a = 20 b = 10

3) What is the output of the following program? - 3 Number value equation

 void main()
{
          int intN = 55;
          int intM = 10;
          char X = 'A' ;
          intN +=50;

          printf("1. Updated value of intN ID % F\N", X);
          printf("2. Updated value of X is % d\n", X);

          X='B';
          printf("3. Updated value of X is % c\n", X);

          intN -=8;
          printf("4. Updated value of intN is %d\n",intN);

          intN++;
          printf("5. Updated value of intN is %d\n", intN);

          intN= intN++  + ++ItM;
          printf("6. Updated value of intN is ;%d intM is;%d\n", intN, intM);
}

Output:
1.Updated value of intN is 105
2.Updated value of X is 65
3.Updated value of X is B
4.Updated value of intN is 97
5.Updated value of intN is 98
6.Updated value of intN is :110 intM is:11

No comments

Comment on Ishwaranand or Happy Day
Not, Add any types of links