C program

 Program No 1: Introduction to C programming language

#include <stdio.h>


int main()

{

    printf("Hello World\n");

    return 0;

}


Output   Hello World


Program No 2  two numbers sum


#include <stdio.h>

int main()
{
    int a, b;
    printf("Enter number a\n");
    scanf("%d", &a);

    printf("Enter number b\n");
    scanf("%d", &b);

    printf("The sum is %d\n", a+b);

    return 0;
}



Program no 3 swapping two numbers without third veriable

#include<stdio.h>
int main()
{
int a, b;
printf("Input value for a & b: \n");
scanf("%d%d",&a,&b);
printf("Before swapping the value of a & b: %d %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping the value of a & b: %d %d",a,b);
return 0;
}
Output



Program no 4 swapping two numbers with third numbers

#include <stdio.h>

#include <conio.h>

int main()

{

int a, b, temp;

clrscr();

printf("Enter two integers\n");

scanf("%d%d", &a, &b);

printf("Before Swapping\n a = %d\n b = %d\n", a, b);

temp = a;

a = b;

b = temp;

printf("After Swapping\n a = %d\n b = %d\n", a, b);

getch();

return 0;

}

Output



Program no 4 swapping two numbers with third veriable

#include<stdio.h>

int main()

{
    
	int a,b,temp;
	printf("Enter a:");
	scanf("%d",&a);

	printf("Enter b:");
	scanf("%d",&b);

	t=a;
	a=b;
	b=temp;
	printf("\nAfter Swap\na:%d b:%d",a,b);  
	return 0;

}



Comments

Popular Posts