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;
}


Comments

krishnakumar comment

 krishnakumar

#include<conio.h>
#include<stdio.h>
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
Scars comment

 Scars

I cant say i did not learn.......Not bad its really helpful


2015-04-19
dj man comment

 dj man

i 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 comment

 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



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.