CLASS WORK ON CONVERSION USING
FUNCTIONS, MAY/31/2013:
- CONVERTING CELSIUS TO FEREHEIT.
- CONVERTING FEREHEIT TO CELSIUS.
- CONVERTING MILLIMETER TO CENTIMETER.
SEE CODE
BELOW:
#include<stdio.h>
void main()
{
int a;
int num, num1, num3;
printf("Please select your conversion
type\n");
printf("\nPress 1 to Convert from
Celsius to Fereheit\nPress 2 to Convert from Fereheit to Celsius\nPress 3 to
convert Centimeter to Millimeter\n");
scanf("%d",&a);
if(a==1)
{
printf("\nPlease enter the
temperature of Celsius\n");
scanf("%d",&num);
printf("The fehereit temperature
is: %d",first(num));
}
else if(a==2)
{
printf("\nPlease enter the
temperature of Fehereit\n");
scanf("%d",&num1);
printf("The Celsius temperature
is: %d",second(num1));
}
else if(a==3)
{
printf("\nPlease enter centimeter
digit\n");
scanf("%d",&num1);
printf("The millimeter is:
%d",third(num1));
}
else
{
printf("You entered an invalid
option");
}
}
int
first(int c)
{
int f=(1.8*c)+32;
return f;
}
int
second(int f)
{
int c=(f-32)/1.8;
return c;
}
int
third(int temp)
{
int
ans=temp*1000000;
return ans;
}
CLASS WORK ON CONVERSION, MAY/28/2013.
1. CELSIUS TO FEREHEIT.
2. CELSIUS TO KELLVIN.
3. FEREHEIT TO CELSIUS.
4. FEREHEIT TO KELVIN.
5. KELVIN TO CELSIUS.
6. KELVIN TO FEREHEIT.
SEE THE CODE
BELOW
#include<stdio.h>
main()
{
int a;
float c,f,k;
char choice;
start:
printf("Temperature
Convertion\n");
printf("1.
Celsius to Fahrenheit\n");
printf("2.
Celsius to Kelvin\n");
printf("3.
Fahrenheit to Celsius\n");
printf("4.
Fahrenheit to Kelvin\n");
printf("5.
Kelvin to Celsius\n");
printf("6.
kelvin to Fahrenheit\n");
printf("Enter
ur choice:");
scanf("%d",&a);
switch(a)
{
case 1:
{
printf("\t\t\tWelcome to Celsius
to Fahrenheit Conversion\n");
printf("Enter Celsius Temperature
to be converted:: ");
scanf("%f",&c);
f=(1.8*c)+32;
printf("The Fahrenheit temperature
is %f\n",f);
printf("Do you want to try another
operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 2:
{
printf("\t\t\tWelcome to Celsius
to Kelvin Conversion\n");
printf("Enter Celsius Temperature
to be converted: ");
scanf("%f",&c);
k=c+273.15;
printf("The Kelvin temperature is
%f\n",k);
printf("Do you want to try another
operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 3:
{
printf("\t\t\tFahrenheit to
Celsius\n");
printf("Enter Fahrenheit
Temperature to be converted: ");
scanf("%f",&f);
c=(f-32)/1.8;
printf("The Celsius temperature is
%f\n",c);
printf("Do you want to try another
operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 4:
{
printf("\t\t\tFahrenheit to
kelvin\n");
printf("Enter Fahrenheit
Temperature to be converted: ");
scanf("%f",&f);
c=(f-32)/1.8;
k=c+273.15;
printf("The Kelvin temperature is
%f\n",k);
printf("Do you want to try another
operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 5:
{
printf("\t\t\tKelvin to
Celsius\n");
printf("Enter Kelvin Temperature
to be converted: ");
scanf("%f",&k);
c=k-273.15;
printf("The Celsius temperature is
%f\n",c);
printf("Do you want to try another
operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 6:
{
printf("\t\t\tKelvin to
Fahrenheit\n");
printf("Enter Kelvin Temperature
to be converted: ");
scanf("%f",&k);
c=k-273.15;
f=(1.8*c)+32;
printf("The Fehrenheit temperature
is %f\n",f);
printf("Do you want to try another
operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
}
}
PRESENTATION: A PROGRAM TO DISPLAY
PRIME NUMBERS BETWEEN 1 AND 1000, MAY/22/2013.
SEE CODE BELOW:
#include<stdio.h>
void main()
{
int num;
int i;
printf("pls
enter to display the prime numbers");
//scanf("%d",&num);
for(num = 2;
num <= 1000; num++)
//printf("the
number is a prime number");
{
for(i=2; i<=num-1; i++)
{
if(num % i==0)
{
//printf("%d
is not a prime no",num);
break;
}
}
if (i==num)
printf("%d \n",num);
}
}
MULTIPLICATION TABLE WITH ARRAY,
MAY/27/2013.
SEE CODE BELOW:
#include<stdio.h>
void main()
{
int i=2;
int k=2;
for(i;i<=12;i++)
{
for(k;k<=12;k++)
{
printf("%d*%d=%d\n",i,k,i*k);
}
}
}
PROGRAMMED CALCULATOR USING
FUNCTIONS, MAY/30/2013.
SEE CODE BELOW:
#include<stdio.h>
void main()
{
int num1,num2,num;
printf("1:addition\n2:substraction\n3:multiplication\n4:division");
scanf("%d",&num);
if(num==1)
{
printf("enter the first number");
scanf("%d",&num1);
printf("enter the second
number");
scanf("%d",&num2);
printf("the result is
%d",add(num1,num2));
printf("\nthanks for using my
calculator\n");
}
else
if(num==2)
{
printf("enter the first number");
scanf("%d",&num1);
printf("enter the second
number");
scanf("%d",&num2);
printf("the result is
%d",subtraction(num1,num2));
printf("\nthanks for using my
calculator\n");
}
else
if(num==3)
{
printf("enter the first number");
scanf("%d",&num1);
printf("enter the second
number");
scanf("%d",&num2);
printf("the result is
%d",multiplication(num1,num2));
printf("\nthanks for using my
calculator\n");
}
else
if(num==4)
{
printf("enter the first number");
scanf("%d",&num1);
printf("enter the second
number");
scanf("%d",&num2);
printf("the result is
%d",division(num1,num2));
printf("\nthanks for using my
calculator\n");
}
else
{
printf("you would be fine
soon!!!");
}
}
int add(int
a,int b)
{
int c=a+b;
return c;
}
int
subtraction(int a,int b)
{
int c=a-b;
return c;
}
int
multiplication(int a,int b)
{
int c=a*b;
return c;
}
int
division(int a,int b)
{
int c=a/b;
return c;
}
CLASS WORK ON POINTERS, MAY/28/2013.
SEE THE
CODE BELOW:
#include<stdio.h>
void main()
{
int a;
int *ptr_var=&a;
a= 20;
printf("%d",*ptr_var);
}
CLASS WORK ON ARRAY NAMES, MAY/27/2013.
SEE CODE
BELOW:
#include<stdio.h>
void main()
{
int i=0;
int k=0;
int num1[2][12]={67,68,90,45,97,34,26,98,89,40,76,96,4,9,3,3,4,5,6,5,90,5,9};
for(i;i<2;i++)
{
for(k;k<24;k++)
{
printf("%d\n",num1[i][k]);
}
{
if(num1[2][1]==2)
{
printf("you are improving");
}
else {
printf("you
are on your own");
}
}
}
}
CLASS WORK ON FOR LOOP, MAY/26/2013.
SEE CODE
BELOW:
#include<stdio.h>
void main()
{
int i=0;
for(i;i<=20;i++)
{
printf("i love u\n");
scanf("%d",&i);
}
}
FOR LOOP TO GET FACTORIAL OF NUMBERS, MAY/26/2013.
SEE CODE
BELOW:
#include<stdio.h>
void main()
{
int fac=1;
int num;
printf("pls enter the number you want
to get the factorial");
scanf("%d",&num);
int i=1;
for(i;i<=num;num--)
{
fac=fac*num;
printf("%d",fac);
}
}
C PROGRAM THAT CHECK’S THE LENGTH OF
A CHARACTER, MAY/31/2013.
SEE CODE
BELOW:
#include<stdio.h>
#include<string.h>
void main()
{
char name1[10];
printf("pls enter name\n");
gets(name1);
int ans=strlen(name1);
printf("the length of the name is
%d",ans);
}
CLASS WORK
ON ARRAY GOTO,MAY/23/2013.
SEE CODE
BELOW:
#include<stdio.h>
void main()
{
int num;
int num2;
printf("Please Press 1 to Start \n
Please Press 2 to End\n");
scanf("%d",&num2);
if (num2==1)
{
goto start;
}
else
{
goto ending;
}
ending: printf("Thanks for using the
software");
start: printf("Please enter the number
of student you want to enter information\n");
scanf("%d",&num);
int id[num];
int mark[num];
int klass[num];
int i=0;
for (i;i<num;i++)
{
printf("Please enter the number %d
student ID\n",i+1);
scanf("%d",&id[i]);
printf("Please enter the number %d
student Score\n",i+1);
scanf("%d",&mark[i]);
printf("Please enter the number %d
student Batch\n",i+1);
scanf("%d",&klass[i]);
}
int num3;
int k=0;
printf("Please press 3 to display
information \n Please press 4 to end the program\n");
scanf("%d",&num3);
if (num3==3)
{
goto info;
}
else
{
goto ending;
}
info: printf("The student information
is displayed below\n");
for(k;k<num;k++)
{
printf("The Student ID is: %d ||
The Score is: %d || The Batch number is: %d \n",id[k],mark[k],klass[k]);
}
}
A PROGRAM THAT SCORE AND GRADE
STUDENTS (USING ARRAY), MAY/24/2013.
SEE CODE
BELOW:
#include<stdio.h>
void main ()
{
int num1,num2,num3,num,num4,num5;
float mark=0;
printf("welcome to c programming
test\n");
printf("\n1:stage1\n2:stage2\n3:stage3");
scanf("%d",&num);
switch(num)
{
case 1:
printf("answer all the questions,
each question carries equal mark\n");
printf("\nwhat is
programming?");
printf("\n1:the act of instructing
the computer on how to perform a specific task\n");
printf("\n2:the act of instructing
the compiler on how to perform a specific task\n");
printf("\n3:the act of instructing
the operating system on how to perform a specific task\n");
scanf("%d",&num1);
if(num1==1)
{
printf("Wow! you are
correct");
mark=mark+5;
}else if(num1==2)
{
printf("wrong option");
}else if(num1==3)
{
printf("wrong option!");
}
else{
printf("invalid
option!");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("question2\n what is an
array?\n");
printf("\n1: a collection of
element \n");
printf("\n2: a collection of
element of the same data type \n");
printf("\n3: a collection of
element of different data type\n");
scanf("%d",&num2);
if(num2==1)
{
printf("wrong option!");
}else if (num2==2)
{
printf("great! you are
correct");
mark=mark+5;
}else if(num2==3)
{
printf("wrong option!");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("question3\n what is a
variable?\n");
printf("\n1: a block where arrays
are stored \n");
printf("\n2: a container in
computer memory where constants and functions are stored \n");
printf("\n3: a container in memory
where values are stored\n");
scanf("%d",&num3);
if(num3==1)
{
printf("wrong option!");
}else if (num3==3)
{
printf("great! you are
correct");
mark=mark+5;
}
else if(num3==2){
printf("wrong option!");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("question4\n what is a
string?\n");
printf("\n1: an array of character
\n");
printf("\n2: a collection of
intergers \n");
printf("\n3: a container in memory
where values are stored\n");
scanf("%d",&num4);
if(num4==1)
{
printf("great! you are
correct");
mark=mark+5;
}else if (num4==2)
{
printf("wrong option!");
}
else if(num4==3){
printf("wrong option!");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("question5\n what is a data
type\n");
printf("\n1: an array of character
\n");
printf("\n2: a type of data stored
in the variable \n");
printf("\n3: a type of data stored
in a memory\n");
scanf("%d",&num5);
if(num5==1)
{
printf("wrong option");
}else if (num5==2)
{
printf("wrong option!");
}
else if(num5==3){
printf("great! you are
correct");
mark=mark+5;
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("thanks for taking our
test\n");
float perc=mark/25 *100;
if(perc>=70)
{
printf("your mark is %f and
your grade is distinction",perc);
}
else if(perc>=60)
{
printf("your mark is %f and
your grade is upper credit",perc);
}
else if(perc>=50)
{
printf("your mark is lower
credit",perc);
}
else if(perc>=40)
{
printf("your mark is %f is
pass",perc);
}
else
{
printf("your mark is %f you
have failed",perc);
}
case 2:
printf("what is a
software?\n");
printf("\n1: it is also called an
operating system \n");
printf("\n2: it is a storage
device \n");
printf("\n3: it is a combination
of two or more programs\n");
scanf("%d",&num1);
if(num1==1)
{
printf("no! you are
wrong");
}else if (num1==2)
{
printf("wrong option!");
}
else if(num1==3){
printf("wow! you are
correct");
mark=mark+5;
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n1: what is a
statement?\n");
printf("\n1: it is a command that
is terminated with a semicolon \n");
printf("\n2: it is just a command
\n");
printf("\n3: it is a memory where
commands are stored\n");
scanf("%d",&num2);
if(num2==1)
{
printf("wow! you are
correct");
mark=mark+5;
}else if (num2==2)
{
printf("wrong option!");
}
else if(num2==3){
printf("wrong option");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n1: what is an
expression? \n");
printf("\n1: it is a combination
of operators and operands \n");
printf("\n2: it is a spoken word
\n");
printf("\n3: it is a command given
to the computer to perfom \n");
scanf("%d",&num3);
if(num3==1)
{
printf("wow! you are
correct");
mark=mark+5;
}else if (num3==2)
{
printf("wrong option!");
}
else if(num3==3){
printf("wrong option");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n1: how many key words
does C have?\n");
printf("\n1: 50key words
\n");
printf("\n2: 32 \n");
printf("\n3: 56 key
words\n");
scanf("%d",&num4);
if(num4==1)
{
printf("wrong option");
}else if (num4==2)
{
printf("wow! you are
correct");
mark=mark+5;
}
else if(num4==3){
printf("wrong option");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n1: what is the full
meaning of stdio.h?\n");
printf("\n1: study in orland head
quaters \n");
printf("\n2: stadard input and
output header\n");
printf("\n3: stadardised income
and outcome hierachy \n");
scanf("%d",&num5);
if(num5==1)
{
printf("wrong option");
}else if (num5==2)
{
printf("wow! you are
correct");
mark=mark+5;
}
else if(num5==3){
printf("wrong option");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("thanks for taking our
test\n");
float perce=mark/25 *100;
if(perce>=70)
{
printf("your mark is %f and
your grade is distinction",perce);
}
else if(perc>=60)
{
printf("your mark is %f and
your grade is upper credit",perce);
}
else if(perc>=50)
{
printf("your mark is lower
credit",perce);
}
else if(perc>=40)
{
printf("your mark is %f is
pass",perce);
}
else
{
printf("your mark is %f you
have failed",perce);
}
case 3:
printf("\n : what is the function
used to start a code?\n");
printf("\n1: curly brace
\n");
printf("\n2: parenthesis
\n");
printf("\n3: main() \n");
scanf("%d",&num1);
if(num1==1)
{
printf("no! you are
wrong");
}else if (num1==2)
{
printf("wrong option!");
}
else if(num1==3){
printf("wow! you are
correct");
mark=mark+5;
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n : what is an algorithm
?\n");
printf("\n1: it is the procedure
or steps on how to go aboout a problem \n");
printf("\n2: it is a storage
device \n");
printf("\n3: it is a combination
of two or more programs\n");
scanf("%d",&num2);
if(num2==1)
{
printf("wow! you are
correct");
mark=mark+5;
}else if (num2==2)
{
printf("wrong option!");
}
else if(num2==3){
printf("no! you are
wrong");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n : what are the two
classes of operators?\n");
printf("\n1: unary and binary
\n");
printf("\n2: bitwis and unary
\n");
printf("\n3: logical and
binary\n");
scanf("%d",&num3);
if(num3==1)
{
printf("wow! you are
correct");
mark=mark+5;
}else if (num3==2)
{
printf("wrong option!");
}
else if(num3==3){
printf("no! you are
wrong");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n : how do you calculate
in microsoft office excel 2007?\n");
printf("\n1: you use the plus sign
\n");
printf("\n2: you use the equal to
sign \n");
printf("\n3: you use the
multiplication sign\n");
scanf("%d",&num4);
if(num4==1)
{
printf("wrong
option!");
}else if (num4==2)
{ printf("wow! you are
correct");
mark=mark+5;
}
else if(num4==3){
printf("no! you are
wrong");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
printf("\n : the following are
exammpls of logical operators except one?\n");
printf("\n1: greater than
\n");
printf("\n2: AND \n");
printf("\n3: you use the multiplication
sign \n");
scanf("%d",&num5);
if(num5==1)
{
printf("wrong
option!");
}else if (num5==2)
{ printf("wow! you are
correct");
mark=mark+5;
}
else if(num5==3){
printf("no! you are
wrong");
}else{
printf("invalid
selection");
}
printf("-----------------------\n");
printf("-----------------------\n");
float perca=mark/25 *100;
if(perca>=70)
{
printf("your mark is %f and
your grade is distinction",perca);
}
else if(perc>=60)
{
printf("your mark is %f and
your grade is upper credit",perca);
}
else if(perc>=50)
{
printf("your mark is lower
credit",perca);
}
else if(perc>=40)
{
printf("your mark is %f is
pass",perca);
}
else
{
printf("your mark is %f you
have failed",perca);
}
}
}
No comments:
Post a Comment