0% found this document useful (0 votes)
22 views

Practical Record Book - Cprog

lab book

Uploaded by

ilanjv40
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Practical Record Book - Cprog

lab book

Uploaded by

ilanjv40
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C PROGRAMMING PRACTICAL RECORD BOOK

BY
KATABALWA JOHN VIANNEY
012220073
BSc.AIT

This is to certify that I have completed the C Programming Practical Record Book for

First semester under the guidance of Mr. Cornelius.

HEAD OF THE DEPARTMENT FACULTY IN CHARGE

(SIGNATURE WITH DATE) (SIGNATURE WITH DATE)

FACULTY OF INFORMATION AND COMMUNICATION TECHNOLOGY INTERNATIONAL


BUSINESS SCIENCE AND TECHNOLOGY UNIVERSITY Plot 11A, Rotary Avenue, Lugogo Bypass,
Kololo, Kampala, Uganda
Questions:
1. Write a C Program to check whether a number is prime or not.
2. Write a program in C for a 2D array of size 3x4 of salaries and print the matrix
and sum.
3. Write a c program to execute the flow chart below:

4. Write a c program which prompts a user for First name, Last name, Age,
Salary (in $) and output 5 records on the console.
//C Program to check whether a number is prime or not//
# include <stdio.h>
int main () {
int num, i, flag = 0;
printf ("Enter any number num:");
scanf ("%d", &num);

for (i = 1; i <= num; i++) {


if (num % i == 0) {
flag++;
}
}

if (flag == 2) {
printf ("num is a Prime number");
}
else {
printf ("num is not a Prime number");
}
return 0;
}
//C program for a 2D array of size 3x4 of salaries and print the matrix and sum//
//Assuming the salaries are fixed point integers//
# include <stdio.h>
int main () {
int matrix[3][4] = {{20,30,40,10},{10,20,30,40},{30,10,20,50}};
int i, j, sum= 0;
printf ("\n Elements in the Matrix are: \n");
for (i = 0 ; i < 3 ; i++) {
for (j = 0; j < 4; j++) {
printf ("\t %d ", matrix[i][j]);
}
printf (" \n ") ;
}
for (i = 0 ; i < 3 ; i++) {
for (j = 0; j < 4; j++) {
sum = sum + matrix[i][j];
}
}
printf ("\t Sum of matrix elements is: %d", sum) ;
return 0 ;
}
//c program to execute the flow chart for the maximum of three variables//
# include <stdio.h>
int main() {
int a, b, c;
printf ("\n Enter the First value:");
scanf ("%d", & a);
printf ("\n Enter the Second value:");
scanf("%d", & b);
printf("\n Enter the Third value:");
scanf("%d", & c);
if (a > b) {
if (a > c) {
printf ("\n First value %d is maximum", a);
}
else {
printf ("\n Third value %d is maximum", c);
}
}
else {
if (b > c) {
printf ("\n Second value %d is maximum", b);
}
else {
printf ("\n Third value %d is maximum", c);
}
}
return 0;
}
//c program which prompts a user for First name, Last name, Age, Salary (in $)
and output 5 records on the console//
#include <stdio.h>
struct payroll {
char name1[20];
char name2[20];
int Age;
float Salary;
};
int main () {
struct payroll record[5];
printf ("\nEnter the payroll data");
for (int i = 0; i<5; i++) {
printf ("\n Enter the First name:");
scanf ("%s",&record[i].name1);
printf ("\n Enter the Last name:");
scanf ("%s",&record[i].name2);
printf("\n Enter Age");
scanf("%d",&record[i].Age);
printf("\n Enter Salary");
scanf("%f",&record[i].Salary);
}
printf ("\nDisplay for the payroll data");
for (int i = 0; i<5; i++) {
printf ("\n %s \t %s\t%d\t%f", record[i].name1, record[i].name2, record[i].Age,
record[i].Salary);
}
return 0;
}

You might also like