2074 Set A Q. No. 1
a. a. What are conditional statements in C? Describe the switch case statement.
Conditional statement in C
Describe switch case statement
b. b. List the different type of loop in C. Explain for loop with example
Explain for loop with example
for loop is the most common type of loop which is used to execute the program statement or block of program statements repeatedly for a certain time. The body of the loop does not execute for a single time if the condition is not satisfied.
syntax of for loop:
for(initialization;condition;increasing/decreasing)
{
body of loop;
}
flow chart of for loop
2074 Set A Q. No. 2
Write a C program to find addition of two matrix of size 2*2 using an array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2], b[2][2], c[2][2], i, j;
printf("\n Enter elements of first (2*2) matrix");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d", &a[i][j]);
}
}
printf("\n Enter elements of second (2*2) matrix");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d", &b[i][j]);
}
}
printf("\n printing sum of matrix");
printf("\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j] = a[i][j] + b[i][j];
printf("%d\t", c[i][j]);
}
printf("\n");
}
getch();
}
Output
2074 Set A Q. No. 3
a. Write a C program to compare any two string by using string function in C
#include<conio.h>
#include<string.h>
void main()
{
char string1[20], string2[20];
printf("\n Enter two string");
scanf("%s%s", string1,string2);
if(strcmp(string1,string2)>0)
{
printf("%s is greater than %s",string1, string2);
}
else if(strcmp(string1,string2)<0)
{
printf("%s is greater than %s",string2,string1);
}
else
{
printf("%s is equal than %s", string1,string2);
}
getch();
}
Output
b. What is pointer in C? Explain
2074 Set A Q. No. 4
Write a program to input the 5 employee’s name and salary using structure and display the records in proper format.
#include<stdio.h>
#include<conio.h>
void main()
{
struct record
{
char name[30];
int sal;
};
struct record a[5];
int i;
printf("\n Enter Name and salary of 5 employee");
for(i=0;i<5;i++)
{
scanf("%s%d", a[i].name, &a[i].sal);
}
for(i=0;i<5;i++)
{
printf("\n Name = %s\tSalary = %d", a[i].name, a[i].sal);
}
getch();
}
Output
2074 Set A Q. No. 5.
Describe the function in C? Write a C program to find the sum of n integer number using function
Describe the function in C?
Write a C program to find the sum of n integer number using function
#include<stdio.h>
#include<conio.h>
void sum(int);
void main()
{
int n;
printf("\n Enter how many number");
scanf("%d", &n);
sum(n);
getch();
}
void sum(int n)
{
int a, i, s=0;
printf("\n Enter %d numbers", n);
for(i=0;i<n;i++)
{
scanf("%d", &a);
s = s + a;
}
printf("\n Sum = %d", s);
getch();
}
Output






0 Comments
Please do not enter any spam link on comment box