Solution of Old is gold|computer programming|grade 12|2074 Set A

Solution of Old is gold|computer programming|grade 12|2074 Set A

 

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

 Click here


b.              b.  List the different type of loop in C. Explain for loop with example

 Different type of loop in C

for loop. 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 loop does not execute for a single time if the condition is not satisfied.

while loop. while loop is an entry control loop where the condition is evaluated at the beginning. It checks the condition at first; if it is found true then it executes the statements written in its body part otherwise it just gets out from the loop structure. It has used the keyword while.

do while loop. do while loop is an exit control loop. It executes program statements once at first then only the condition is checked. Thus, the body of the loop will execute for a single time if the condition is not satisfied at the very first attempt. If the condition is found true then it executes the program statements again, otherwise, it gets out from the loop structure.

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 

Example

Write a program to print 1 to n using for loop

 #include<stdio.h>

#include<conio.h>

void main()

{

int i, n;

printf("\n Enter the value of n:");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

printf("%d\t",I);

}

getch();
Output

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<stdio.h>

#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?

 Click here

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

 

Post a Comment

0 Comments