0% found this document useful (0 votes)
16 views8 pages

Algorithm

The document contains code snippets for C programs that check dice rolls, evaluate polynomial functions, and classify electromagnetic radiation based on frequency. The programs use conditional statements like if-else and scanf to get user input.

Uploaded by

aHealthyKidney
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Algorithm

The document contains code snippets for C programs that check dice rolls, evaluate polynomial functions, and classify electromagnetic radiation based on frequency. The programs use conditional statements like if-else and scanf to get user input.

Uploaded by

aHealthyKidney
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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