DO NOT MISS

Ads

Monday 11 July 2016

C-Programs using Arithmetic Operators


* Write a Program to input Sum of Two Numbers.

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

void main( )

{

      int a,b,c;
      clrscr( );

     
a = 10;
      b = 20;
      c = a + b;

             printf("Sum : %d\n",c);
             printf("%d and %d sum is %d\n",a,b,c);
             printf("%d is the sum of %d and %d\n",c,a,b);
             printf("%d + %d = %d",a,b,c);


     getch( );

}
Output:-

Sum : 30
10 and 20 sum is 30
30 is the sum of 10 and 20
10 + 20 = 30

* write a program to perform all arithmetic operations.

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

void main()

{

       int a,b,c,d,e,f,g;
       clrscr();

     
 printf("enter a b values:\n");
       scanf("%d%d",&a,&b);

       c=a+b;
       d=a-b;
       e=a*b;
       f=a/b;
       g=a%b;

           printf("\n addition=%d",c);
           printf("\n subtraction=%d",d);
           printf("\n multiplication=%d",e);
           printf("\n division=%d",f);
           printf("\n modulo division=%d",g);

      getch();

}

Output:-

Enter a b values:
10
5



Addition=15
Subtraction=5
Multiplication=50
Division=2
Modulo division=0

* write a program to perform arithmetic operation by using only two Variables.

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

void main()

{

       
int a,b;
       clrscr();

       printf("enter a b values:\n");
       scanf("%d%d",&a,&b);

               printf("\n addition=%d",a+b);
               printf("\n subtraction=%d",a-b);
               printf("\n multiplication=%d",a*b);
               printf("\n division=%d",a/b);
               printf("\n modulo division=%d",a%b);

getch();

}
Output:-

Enter a b values:
8
4



Addition=12
Subtraction=4
Multiplication=32
Division=2
Modulo division=0

* Write a Program to perform no of days & convert them convert into no of weeks & remaining days.

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

void main()

{

         int days,weeks,rdays;
         clrscr();

         
printf(“enter no of days:”);
         scanf(“%d”,&days);

         weeks=days/7;
         rdays=days%7;

                 printf(“no of weeks is=%d\n”,weeks);
                 printf(“no of rdays is=%d”,rdays);

        getch();

}

Output:-

Enter no of days: 200
No of weeks is=28 
No of rdays is=4              
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims