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

IF STATEMENT

Write a problem that will know if an individual is addicted to FaceBook or not.

#inlclude<stdio.h>
int h;
main()
{
clrscr();
printf("\n Enter number of hours you spent in FaceBook: ");
scanf("%d",&h);
if (h<=4)
printf("\n Great! You're not yet addicted.");
else if (h>4)
printf("\n **CERTIFIED FaceBookaholic!!!**");
getch();
}

Produce a program that will help the students to know if they can still pursue their
course.

#include<stdio.h>
float ave;
main()
{
clrscr();
printf("\n Enter your average grade: ");
scanf("%f",&ave);
if(ave>3.0)
printf("\n Sorry, you have to shift another course");
else if (ave<=3.0)
printf("\n Great! You can still pursue you recent course.");
getch();
}
IF-ELSE STATEMENT

Write a program that will ask the user input an integer then output the equivalent day
of the week. 1 is Sunday, 2 is Monday, and so on. If the inputted number is not within 1 – 7
output “Day is not available!”
#include<stdio.h>
main()
{
Int day;
printf(“Enter an integer:”);
scanf(“%d”, &day);
if (day == 1)
printf(“Sunday”);
else if (day ==2)
printf(“Monday”);Else if (day ==3)
printf(”Tuesday”); Else if (day ==4)
printf(“Wednesday”);
else if (day ==5)
printf(“Thursday”);
else if (day ==6)
printf(“Friday”); Else if (day ==7)
printf(“Saturday”);
else
printf(“Day is not available!”);
getch();
}

WHILE LOOP

Write a program that will tell if a number is an odd number.

#include <stdio.h>

int main () {
unsigned i;

i = 0;
while (i < 10) {
if (i % 2 == 1) {
printf("%u is an odd number\n", i);
}
++i;
}
return 0;
}

ONE DIMENSIONAL ARRAY


` Create a program that can print out the standard deviation and mean of the entered
numbers.
#include<stdio.h>
#define max_entry 10
float x[max_entry],mean,s,sum,sum_sqr;
int i;
main()
{
printf("Enter %d numbers separated by space or <enter>\n",max_entry);
for(i=0;i<max_entry;++i)
scanf("%f",&x[i]);
sum=0;
sum_sqr=0;
for(i=0;i<max_entry;++i)
{ sum+=x[i];
sum_sqr+=x[i]*x[i];
}
mean=sum/max_entry;
s=(max_entry*sum_sqr-sum*sum)/(max_entry*(max_entry-1));
printf("The mean is %.2f.\n",mean);
printf("The standard deviation is %.2f.\n",s);
getch();
}
MULTIDIMENSIONAL ARRAY
Write a program that will print out numbers in 3D array using multidimensional array.

#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
int arr[3][3][3]=
{
{
{11, 12, 13},
{14, 15, 16},
{17, 18, 19}
},
{
{21, 22, 23},
{24, 25, 26},
{27, 28, 29}
},
{
{31, 32, 33},
{34, 35, 36},
{37, 38, 39}
},
};
clrscr();
printf(":::3D Array Elements:::\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
printf("%d\t",arr[i][j][k]);
}
printf("\n");
}
printf("\n");
}
getch();
}

FUNCTIONS

FUNCTION WITH NO ARGUMENTS AND NO RETURN VALUE

Write a program that will print out ‘Welcome to Function in C” using function with no
arguments and no return value.

#include<stdio.h>
#include<conio.h>
void printline()
{
int i;
printf("\n");
for(i=0;i<30;i++)
{
printf("-");
}
printf("\n");
}
void main()
{
clrscr();
printf("Welcome to function in C");
printline();
printf("Function easy to learn.");
printline();
getch();
}

FUNCTION WITH ARGUMENTS AND NO RETURN VALUE


Write a C program that will print the sum of 30 and 15, 63 and 49, 952 and 321 using
function with arguments and no return value.

#include<stdio.h>
#include<conio.h>
void add(int x, int y)
{
int result;
result = x+y;
printf("Sum of %d and %d is %d.\n\n",x,y,result);
}
void main()
{
clrscr();
add(30,15);
add(63,49);
add(952,321);
getch();
}

FUNCTIONS WITH ARGUMENTS AND RETURN VALUE


Produce a program that will print out the sum of 952+321 and 30+55 using function
with arguments and return value.
#include<stdio.h>
#include<conio.h>
int add(int x, int y)
{
int result;
result = x+y;
return(result);
}
void main()
{
int z;
clrscr();
z = add(952,321);
printf("Result %d.\n\n",add(30,55));
printf("Result %d.\n\n",z);
getch();
}

You might also like