﻿ C exercises and solutions: C arithmetic compound operators

# C exercises and solutions: C arithmetic compound operators

## C arithmetic compound operators exercises

### 1. Write C code to produce the output as shown below:

Results:
x value                 y value        expressions          results
10      |                  5        |         x=y+3                  |    x=8
10      |                  5        |         x=y-2                   |    x=3
10      |                  5        |         x=y*5                   |   x=25
10      |                  5        |         x=x/y                    |   x=2
10      |                  5        |         x=x%y                  |   x=0

Solution

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int x;
int y;
x=10;
y=5;
printf("Result:\n");
printf("x value\t y value\t Expressions\t Result\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x=y+3\t \t| x=%d",y+3);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x=y-2\t \t| x=%d",y-2);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x=y*5\t \t| x=%d",y*5);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x=x/y\t \t| x=%d",x/y);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x=x mody\t| x=%d",x%y);printf("\n");

system("PAUSE");
return 0;
}

### 2. Write a program to produce the output as shown below:

Results:

x value                 y value        expressions          results
10      |                  5        |         x+=y                    |         x=15
10      |                  5        |         x-=y-2                  |         x=7
10      |                  5        |         x*=y*5                 |         x=250
10      |                  5        |         x/=x/y                   |         x=5
10      |                  5        |         x%=y                    |         x=0

Solution
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int x;
int y;
x=10;
y=5;
printf("Result:\n");
printf("x value\t y value\t Expressions\t Result\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x+=y\t \t| x=%d",x+y);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x-=y-2\t \t| x=%d",x-y+2);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x*=y*5\t \t| x=%d",x*y*5);printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x/=x/y\t \t| x=%d",x/(x/y));printf("\n");
printf("%d",x);printf("   |\t %d",y);printf("   |\t x=x mod y\t| x=%d",x%y);printf("\n");

system("PAUSE");
return 0;
} krishnakumar#include #include void main() { int i,j; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); } printf("\n"; } getch(); } 2017-01-06 ScarsI cant say i did not learn.......Not bad its really helpful2015-04-19 dj mani don't know wt i have to say i don't have any ability or mind to accept this cours.beyond my capacity.2014-06-25 Preciousâ€¢ 1. Marcy's Department store is having a BoGotto(Buy One,Get One HalfOff) sale. The store manager wants a program that allows the salescheck to enter the prices of two items. The program should both calculate and display the total amount the customer ones. The half off should always be taken on the item having the lowest price. for example if the item cost \$24.99 and \$10 the half off would be taken on the \$10 item. a. create a flowchart for the problem, and then test the program w/ the following for the first test, use 24.99 and 10 as the prices. For the second test, use 11.50 & 30.99 2013-08-07