Basic Programming Lab
Basic Programming Lab
— — 0x08
1D-Array
// Program to declare and initialise 1D Array
#include <stdio.h>
int main()
{
int arr[10];
/*
Another type of declaration
int arr[] = {1,2,3,4,5}; //array of size 5
*/
// Program to search an element in an array
#include <stdio.h>
int main()
{
int arr[10], x, flag = 0;
}
if (flag == 0)
{
printf("\nSearch Unsuccessful");
}
return 0;
}
Strings
// Program to declare and initialise character
type Array
#include <stdio.h>
int main()
{
char arr[100];
printf("\nEnter the Name:");
scanf("%s", arr);
printf("%s\n", arr );
return 0;
}
/*
scanf alternative
gets(arr);
*/
Formatting output in printf
printf("\n |%5s|",
Width 5 |Programming|
"Programming");
printf("\n |%20s|",
Width 20 | Programming|
"Programming");
Input : 3 coordinates
Output:
If triangle cannot be drawn: no
If triangle can be drawn but not equilateral: yes, Not Equilateral
If triangle can be drawn and equilateral: yes, Equilateral
/*
--------------------------------------------------
|Author : Your_Name |
|Roll No: Your_Roll_No |
|Department: Your_Department |
--------------------------------------------------
*/
Character Functions
Function Description
Returns a non-zero if c is alphabetic or
ialnum(c)
numeric
isalpha(c) Returns a non-zero if c is alphabetic
Returns a non-zero if c is a control
scntrl(c)
character
Function Description
strcpy(s1,s2) Copies s2 into s1