NEW
Font size
WorksheetsPROGRAMMING IN C
Total questions: 13
Worksheet time: 7mins
is a collection of multiple data items, all of the same data type, accessed using a common name.
data
Array
Structure
pointer
Eg :int arr[5]={1,2,3,4,5};
Above example is of___
array
declaration of array
initialization of two dimentional array
compile time Initialization of one dimentional array
Eg : int arr[5]; for(i=0;i<5;i++) {
scanf(“%d”,&arr[i]); }
above code is example of___
array
two dimentional array
runtime Initialization of one dimentional array
Initialization can be done like : char str[4]={'x','y','z','\0'};
OR
char message[10] = "Hello";
array
string
integer
Character Array
Initialization can be done like : int arr[4]={10,20,30,40};
Array
Integer Array
character array
String
___array is a collection of similar type of data elements arranged in the form of rows & columns.
E.g. Array can be declared as int arr[3][3];
Multi-dimensional array
one dimensional array
Two dimensional array
string array
An array with more than one dimensionis called as____
string
pointer
array
Multi-dimensional array
#include <stdio.h>
struct student {
char name[20];
char c[20]; // Assuming 'c' stands for class
int per; // Assuming 'per' stands for percentage
};
int main() {
struct student s[3];
int i;
// Input loop
for(i = 0; i < 3; i++) {
printf("\nEnter details for student %d:\n", i+1);
printf("Name: ");
scanf("%19s", s[i].name); // Limiting input to prevent buffer overflow
printf("Class: ");
scanf("%19s", s[i].c);
printf("Percentage: ");
scanf("%d", &s[i].per);
// Clear input buffer
while(getchar() != '\n');
}
// Output loop
printf("\nStudent Details:\n");
printf("Name\t\tClass\tPercentage\n");
printf("--------------------------------\n");
for(i = 0; i < 3; i++) {
printf("%-15s %-10s %d%%\n", s[i].name, s[i].c, s[i].per);
}
return 0;
}
What is the purpose of the struct student definition in the program?
To create a loop for student data
To define a custom data type for storing student details
To initialize an array of students
To print student information
How many student records can the array struct student s[3]; store?
1
2
4
3
Declare a structure student with element roll-no and name.
struct student
int roll_no;
char name[20];
struct student {
int roll_no;
char name[20];
};
struct student {
int roll_no;
char name[20];
}
struct student {
char name[20];
};
Define array. List its type..? select correct ans.?
Array is a fixed-size sequential collection of elements of the same type
Array is a fixed-size sequential collection of elements of the same type.
Types: 1. One dimensional
Multi dimensional
Array is a fixed-size sequential collection of elements of the same type.
1. One dimensional
2.Two dimensional
3.Multi dimensional
Array is a fixed-size sequential collection of elements of the same type.
1. One dimensional
Define structure. Give one example of structure declaration.?select correct ans.?
Definition of Structure: Structure is a collection of variables of similar or different data types which is represented by a single name.
Example:
struct bill {
int consumer_id;
char address[50];
float amount;
};
Structure is a collection of variables of similar or different data types which is represented by a single name.
struct bill {
int consumer_id;
char address[50];
float amount;
};
struct bill {
char address[50];
float amount;
};
#include <stdio.h>
int main() {
int a[5], i, sum = 0;
printf("Enter 5 array elements:\n");
for (i = 0; i < 5; i++)
{
scanf("%d", &a[i]);
}
for (i = 0; i < 5; i++)
{
sum += a[i];
}
printf("Sum = %d\n", sum);
return 0;
}
select correct output..?
Enter 5 array elements:
10 20 30 40 50
Sum = 150
10 20 30 40 50
Sum = 150
Enter 5 array elements:
10 20 30 40 50
Enter 5 array elements:
10 30 40 50
Sum = 150
