/*Hello World in C */
#include<stdio.h> /* it is Standard I/O Library header file */
#include<conio.h> /* it is Console I/O Library header file */
main()
{
clrscr(); /* To Clear the previous output*/
printf("Hello, World"); /* To print the text (Output)*/
getch(); /* To get a character ,used to wait output until press any key */
}
//Hello World in C+ +
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr(); //To Clear the previous output
cout<<"Hello, World"; //It's like printf() in 'C' (Output)
return 0;
getch();
}
#include<stdio.h> /* it is Standard I/O Library header file */
#include<conio.h> /* it is Console I/O Library header file */
main()
{
clrscr(); /* To Clear the previous output*/
printf("Hello, World"); /* To print the text (Output)*/
getch(); /* To get a character ,used to wait output until press any key */
}
//Hello World in C+ +
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr(); //To Clear the previous output
cout<<"Hello, World"; //It's like printf() in 'C' (Output)
return 0;
getch();
}
Swapping Logic:
I)
a=a+b
b=a-b
a=a-b
ex: Before Swapping a=4,b=5
Logic:a=4+5=9
b=9-5=4
a=9-4=5
After Swapping a=5,b=4
III)
a=a*b
b=a/b
a=a/b
ex: Before Swapping a=4,b=5
Logic:a=4*5=20
b=20/5=4
a=20/4=5
After Swapping a=5,b=4
a=a^b
b=a^b
a=a^b
ex: Before Swapping a=4,b=5
Logic:a=(0010)^(0101)=0111=7
b=(0111)^(0101)=0010=4
a=(0111)^(0010)=0101=5
After Swapping a=5,b=4
a=a+b-(b=a)
ex: Before Swapping a=4,b=5
Logic:a=(4+5)-(4)
=9-4=5
After Swapping a=5,b=4
/* To print welcome without Semicolon */
#include<stdio.h>
#include<conio.h>
main()
{
if(printf("Hello"))
{
}
getch();
}
/*Sum of Digits in Single Statement */
#include<stdio.h>
#include<conio.h>
main()
{
int n,sum=0;
clrscr(); /* To Clear the previous output*/
printf("Enter Any Number"); /* To print the text */
scanf("%d",&n); /* To store the 'n' value from user (input)*/
sum=n%9; /* Simple logic for sum of digits */
if(sum==0){ /*check the condition */
printf("Sum of Digits of %d is:9",n);
}
else {
printf("Sum of Digits of %d is :%d ",n,sum);
}
getch(); /* To get a character ,used to wait output until press any key */
}
I)
a=a+b
b=a-b
a=a-b
ex: Before Swapping a=4,b=5
Logic:a=4+5=9
b=9-5=4
a=9-4=5
After Swapping a=5,b=4
III)
a=a*b
b=a/b
a=a/b
ex: Before Swapping a=4,b=5
Logic:a=4*5=20
b=20/5=4
a=20/4=5
After Swapping a=5,b=4
IV)
a=a^b
b=a^b
a=a^b
ex: Before Swapping a=4,b=5
Logic:a=(0010)^(0101)=0111=7
b=(0111)^(0101)=0010=4
a=(0111)^(0010)=0101=5
After Swapping a=5,b=4
V)
a=a+b-(b=a)
ex: Before Swapping a=4,b=5
Logic:a=(4+5)-(4)
=9-4=5
After Swapping a=5,b=4
/* To print welcome without Semicolon */
#include<stdio.h>
#include<conio.h>
main()
{
if(printf("Hello"))
{
}
getch();
}
/*Sum of Digits in Single Statement */
#include<stdio.h>
#include<conio.h>
main()
{
int n,sum=0;
clrscr(); /* To Clear the previous output*/
printf("Enter Any Number"); /* To print the text */
scanf("%d",&n); /* To store the 'n' value from user (input)*/
sum=n%9; /* Simple logic for sum of digits */
if(sum==0){ /*check the condition */
printf("Sum of Digits of %d is:9",n);
}
else {
printf("Sum of Digits of %d is :%d ",n,sum);
}
getch(); /* To get a character ,used to wait output until press any key */
}

No comments:
Post a Comment