Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Ex1

Ex2
Ex3

#include <stdio.h>

int main(void) {

int dice1;

int dice2;

int product;

scanf("%d %d", &dice1, &dice2);

if (dice1<6 && dice1>1 && dice2<6 && dice2>1)

product=dice1*dice2;

if (product>13)

printf("You win");

else

printf("You loose");

else

if (dice1==1 || dice2==1)

printf("Tie");

else

printf("Invalid Input");

}
Ex4

#include <stdio.h>

int main(void) {

int x;

int answer;

int answer2;

scanf("%d", &x);
if (x<=-2)

answer=x*x*x + 3*x + 4;

if (x>-2 && x<=1)

answer2=x*x-4*x;

if (answer2>=0)

answer=7*x*answer2;

else if (answer2<0)

answer2=answer2*-1;

answer=7*x*answer2;

else if (x>1)

answer=x*x*x+5;

printf("%d",answer);

}
Ex5

#include <stdio.h>

#include <math.h>

int main(void) {

float coeff;

int expo;

double sum1;

double sum2;

scanf("%f %d", &coeff, &expo);

sum1=pow(10,expo);
sum2=sum1*coeff;

if (sum2<3*pow(10,9))

printf("Radiowaves");

if (sum2>3*pow(10,9) && sum2<3*pow(10,12))

printf("Microwaves");

if (sum2>3*pow(10,12) && sum2<4.3*pow(10,14))

printf("Infrared Lights");

if (sum2>4.3*pow(10,14) && sum2<7.5*pow(10,14))

printf("Visible Light");

if (sum2>7.5*pow(10,14) && sum2<3*pow(10,17))

printf("Ultraviolet Light");

if (sum2>3*pow(10,17) && sum2<3*pow(10,19))

printf("X-Rays");

if (sum2>3*pow(10,19))

printf("Gamma Rays");

Trace example1
Trace example2;

Trace example3;

You might also like