#include <stdio.
h>
int main()
{
int x;
do
{
printf("enter the number");
scanf("%d",&x);
}while(x>0);
}
Switch Case
Multi selection statement
#include <stdio.h>
int main()
{
int x;
printf("enter the day value");
scanf("%d",&x);
x=x%7;
switch(x)
{
case 0:
{
printf("SUNDAY");
break;
}
case 1:
{
printf("MONDAY");
break;
}
case 2:
{
printf("TUEDAY");
break;
}
case 3:
{
printf("wednesDAY");
break;
}
case 4:
{
printf("thrusDAY");
break;
}
case 5:
{
printf("FriDAY");
break;
}
default:
{
printf("saturday");
}
}
}
#include <stdio.h>
#include<math.h>
# define pi 3.14
int main()
{
float r,cir,area;
printf("enter the Radius");
scanf("%f",&r);
cir= 2*r*pi;
area= pi* pow(r,2);
printf("the circum is: %0.2f\nthe area is : %0.2f", cir, area);
}
Storage Classes - helps to understand the scope of the variables
Auto / Local variables- persistent of the variable is within the scope.
Extern/ Global Variables- persistent of the variable is through the program.
Register Variables- Fast variables.
Static variables- live the variable to other scopes.
https://www.geeksforgeeks.org/storage-classes-in-c/
UNIT IV ARRAYS
- Derived data type
- Collections of data of same data type;
- Store the n number values in the same name
- Indexing is used to locate the values
- Declare the arrays
- Datatype arrayname[value];
- int a[10];
- Index is from 0 to 9
-
Single dimensional Arrays 1D array.
int main()
{
int a[10],i, n;
printf("enter the number of elements to be stored");
scanf("%d",&n);
printf("enter the elements");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}
#include <stdio.h>
int main()
{
int a[10],b[10],c[10],i, n;
printf("enter the number of elements to be stored");
scanf("%d",&n);
printf("enter the elements of a");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the elements of b");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
c[i]= a[i]+b[i];
}
printf("the result is\n");
for(i=0;i<n;i++)
{
printf("%d\t",c[i]);
}
}