0% found this document useful (0 votes)
7 views

C Programming

The document contains several C programming code snippets demonstrating basic concepts such as loops, switch-case statements, and arrays. It explains storage classes in C, including auto, extern, register, and static variables. Additionally, it provides examples of single-dimensional arrays and operations like element storage and addition of two arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C Programming

The document contains several C programming code snippets demonstrating basic concepts such as loops, switch-case statements, and arrays. It explains storage classes in C, including auto, extern, register, and static variables. Additionally, it provides examples of single-dimensional arrays and operations like element storage and addition of two arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#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]);
}
}

You might also like