Tuesday, December 30, 2014

Swapping and Arithmatic Functions in c pro



Swapping Program

#include
#include
void main()
int a,b;
clrscr();
          printf("Enter a,b value\n");
          scanf("%d%d",&a,&b);
          a=a+b;
          b=a-b
          a=a-b;
          printf("After swapping\n");
          printf("\n A value : %d",a);
          printf("\n B value : %d",b);
getch();
}

Output
         
          Enter a,b value
          5
          10
          After swapping
          A value : 10
          B value : 5

Program 1

#include
#include
void main()
{
int a,b,c,tot;
clrscr();
          printf("Enter a value");
          scanf("%d",&a);
          printf("Enter b value");
          scanf("%d",&b);
          printf("Enter c value");
          scanf("%d",&c);
          tot=a+b+c;
          printf("\n Total              : %d",tot);
getch();
}

Output
          
           Enter a value
          10
          Enter b value
          15
          Enter c value       
          5
          Total  : 30

Program 2

#include
#include
void main()
{
char name[10];
int m1,m2,total;
clrscr();
          printf("\n Enter the student name\n");
          scanf("%s",name);        
          printf("\n Enter the m1,m2\n");
          scanf("%d%d",&m1,&m2);
          total=m1+m2;
          printf(\n Total      : %d",total);
getch();
}

Output
        
          Enter the student name
          Raja
          Enter the m1,m2
          80
          70
          Total : 150

Program 3

#include
#include
void main()
{
int a,b,add,sub,mul,div;
clrscr();
          printf("Enter the a,b values\n");       
          scanf("%d%d",&a,&b);
          add=a+b;
          sub=a-b;
          mul=a*b;
          div=a/b;
          printf("\n Addition                  :%d",add);
          printf("\n Subtraction    :%d",sub);
          printf("\n Multiplication          :%d",mul);
          printf("\n Division                   :%d",div);
getch();
}

Output
         
          Enter the a,b values
          10
5
Addition               : 15
Subtraction          :5
Multiplication      : 50
Division               : 2

Program 4

#include
#include
void main()
{
char name[20];
int age;
float height;
clrscr();
          printf("Enter ur name\n");
          scanf("%s",name);
          printf("Enter ur age\n");
          scanf("%d",&age);
          printf("Enter ur height\n");
          scanf("%f",&height);
          printf("Name        :%s",name);
          printf("Age           :%d",age);
          printf("Height       :%f",height);
getch();
}

Output
          
          Enter ur name
          Ragul
Enter ur age
          23
          Enter ur height
          6.2
          Name          : Ragul
          Age             : 23
          Height         : 6.2

No comments:

Post a Comment