Print A Design-IV

Print the following design:

   *
  * *
 * * *
* * * *



#include<stdio.h>
#include<conio.h>
main()
{
  int k,x;
  clrscr();
  for(i=1;i<5;i++)
  {
  for(x=5-i;x>1;x--)
     printf(" ");
  for(k=1;k<=i;k++)
     printf("* ");
  printf("\n");
  }
  return 0;
}

Print A Design-III

Print the following design:

   1
  212
 32123
4321234



#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,x;
clrscr();
for(i=1;i<5;i++)
{
for(x=5-i;x>1;x--)
  printf(" ");
for(j=i;j>=1;j--)
  printf("%d",j);
for(k=2;k<=i;k++)
  printf("%d",k);
printf("\n");
}
return 0;
}

Print A Design-II

Print the following design:

A
AB
ABC
ABCD



#include<stdio.h>
#include<conio.h>
main()
{
  int i,j;
  char ch;
  clrscr();
  for(i=1;i<5;i++)
  {
   for(j=1,ch='A';j<=i;j++,ch++)
    printf("%c",ch);
   printf("\n");
  }
  return 0;
}

Print A Design-I

Print the following design:

$
$$
$$$
$$$$



#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j;
  clrscr();
  for(i=1;i<5;i++)
  {
   for(j=1;j<=i;j++)
    printf("$");
  printf("\n");
  }
  return 0;
}

Addition Operation

C program to add two numbers and display the result.


#include<stdio.h>
#include<conio.h>
main()
{
int a,b,sum;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
sum=a+b;
printf("The sum is %d",sum);
return 0;
}

Addition Of The Digits Of A Number

C program to add all the digits of a number and print the sum.


#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,x;
clrscr();
printf("Enter a five digit number: ");
scanf("%d",&x);
a=x%10; x/=10;
b=x%10;         x/=10;
c=x%10; x/=10;
d=x%10; x/=10;
printf("\nSum of all the digits of the number is %d",a+b+c+d+x);
return 0;
}

Swapping Numbers

C program to swap two numbers.


Method 1:

Using only two variables

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("Enter two numbers a and b: ");
scanf("%d %d",&a,&b);
a+=b;
b=a-b;
a-=b;
printf("\nAfter swapping, a: %d and b: %d",a,b);
return 0;
}


Method 2:

Using three variables

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter two numbers a and b: ");
scanf("%d %d",&a,&b);
temp=a;
a=b;
b=temp;
printf("\nAfter swapping, a: %d and b: %d",a,b);
getch();
}


Method 3:

Using bitwise operator

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two numbers a and b: ");
scanf("%d %d",&a,&b);
a=a^b;
b=a^b;
a=a^b;
printf("\nAfter swapping, a: %d and b: %d",a,b);
getch();
}

Temperature Coversion

C program to convert temperature in degree Celsius to degree Fahrenheit and vice-versa.


#include<stdio.h>
#include<conio.h>
main()
{
float c,f;
printf("Enter temperature in Celsius: ");
scanf("%f",&c);
f=((9*c)/5)+32;
printf("\nCorresponding temperature in Fahrenheit: %f",f);
printf("\nEnter temperature in Fahrenheit: ");
scanf("%f",&f);
c=((f-32)*5)/9;
printf("\nCorresponding temperature in Celsius: %f",c);
return 0;
}

Print A Message

C program to print a message.


#include<stdio.h>       // for printf()
#include<conio.h>      // for clrscr()
main()
{
    clrscr();
    printf("Hello People!");
}
/******************
To view the result,
press Alt+F5
******************/