Computer Final BackGround Theory
Computer Final BackGround Theory
Computer Final BackGround Theory
(COMPUTER SCIENCE)
KATHMANDU, NEPAL
2023
ACKNOWLEDGEMENT
Last but not least, I would like to express my gratitude to my parents, friends,
this college, and anyone else who has assisted me for their guidance and
encouragement.
Nish Adhikari
Objective
Objective is a specific result that a person, a system aims to achieve within a time
frame and with avid able resources. In general, objectives are more specific and
easier to measure than goals. Objectives are basic tools that underlie all
planning and strategic activities. They serve as a basic forecasting policy and
evaluating performance.
I) ‘for’ loop
Example:
#include<stdio.h>
Void main()
int i, fact=1;
for(i=1;i<=5;i++)
fact=fact*i;
Example:
#include<stdio.h>
Void main()
Example:
#include<stdio.h>
void main()
{
/* program to display multiplication table of 5 */
int i=1; //initialization
int p;
do
{
p=5*i;
printf(“\n6*%d = %d”,I,p);
i++; //increment
} while(i<=10); //condition
}
Q5. What is an array? Explain different types of array.
- An array is a collection of similar types of data items treated as a single
unit. It acts to store related data under the same name with an index, also
known as a subscript which helps to access individual array elements.
- There are two types of arrays which are as follows:
#include<stdio.h>
#include<string.h>
void main()
{
char str[49];
printf(“Enter a string:”);
gets(str);
printf(“The string in lower-case is: %s”,strlwr(str));
strupr()- To convert lower case characters of strings into upper case characters.
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char str[49];
printf(“Enter a string:”);
gets(str);
printf(“The string in lower-case is: %s”,strupr(str));
strlen()- To return the length of a string which takes the string name as an
argument.
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char str[50];
int l;
printf(“Enter a string:”);
gets(str);
l=strlen(str);
printf(“The length of the string is: %d”, l);
}
strcat()- To join or concatenate one string into another string. It takes two strings
and the second string is concatenated over the first string.
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char str1[50],str2[60];
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char str;
printf(“Enter the string:”);
gets(str);
strrev(str);
printf(“The reverse of given string is %s, str);
}
}
strcpy()- To copy one string into another string.
Example:
#include<stdio.h>
#include<string.h>
void main()
{
char str1[50],str2[50];
printf(“Enter first string:”);
gets(str1);
strcpy(str2,str1);
printf(“After copying the string is %s.”,str2);
}
Q8. Write differences between for loop and while loop
-
Q9. Write differences between while loop and do while loop