0% found this document useful (0 votes)
2 views14 pages

Labcode C

The document contains a collection of C programming exercises that cover various topics such as arithmetic operations, temperature conversions, number classification, triangle validation, grading systems, leap year checks, and array manipulations. Each exercise includes a brief description followed by the corresponding C code implementation. The programs demonstrate fundamental programming concepts like loops, conditionals, and user input handling.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

Labcode C

The document contains a collection of C programming exercises that cover various topics such as arithmetic operations, temperature conversions, number classification, triangle validation, grading systems, leap year checks, and array manipulations. Each exercise includes a brief description followed by the corresponding C code implementation. The programs demonstrate fundamental programming concepts like loops, conditionals, and user input handling.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Write a c programme to enter two numbers and find their Sum

#include<stdio.h> //Header file


int main() //Main function
{
int a,b,result; //Data type
printf("Enter the number : ");
scanf("%d %d",&a,&b); //Input from user

result=a+b; //Adding two numbers


printf("sum is=%d\n",result); //Output the result

return 0;

[Link] a c programme to enter two numbers and find their Submission

#include<stdio.h>
int main()
{
int a,b,result;
float c;
printf("Enter the number : ");
scanf("%d %d",&a,&b);

c=(float)a/b;
printf("Div is=%.2f\n",c);
Return 0;

}
[Link] a c programme to enter base and height of a triangle and find its area

#include<stdio.h>
int main()
{

float base,height,area;
printf("Enter the Base value : "); //Input base and height of triangular from user
scanf("%f %f",&base,&height);

area=(float)1/2 * base * height; //calculate the area of triangle


printf("The area is=%.2f\n",area);

return 0;
}

[Link] a c programme to inter temperature in celsius and convert it into Fahrenheit

#include<stdio.h>
int main()
{
float c,f;
printf("Enter the celcius temperature : ");
scanf("%f",&c); //input celsius from user
f=((9*c)/5)+32; //calculate farenheit
printf("The fahrenheit temperature is=%.2f\n",f);
return 0;
}
[Link] a c programme to inter temperature in Fahrenheit and convert it into celsius

#include<stdio.h>

int main()
{
float c,F;
printf("Enter the fahrenheit temperature : ");
scanf("%f",&F);
c=(5*(F-32)/9);
printf("The centigrade temperature is=%.2f\n",c);
return 0;
}

[Link] a c programme to check whether a number is positive,negative or zero

#include<stdio.h>
int main()
{
int num;
/*input from the user*/
printf("Enter a number :");
scanf("%d",&num);

/*If num>0 number is positive


If num<0 number is negative*/

if(num>0)

{
printf("%d number is Positive\n",num);
}

else if(num<0)
{
printf("%d number is Negative\n",num);
}

else
{
printf("%d number is Zero\n",num);
}
return 0;
}

[Link] a c programme to check whether a number is divisible by 5 and 11 or not

#include<stdio.h>
int main()
{
int num;
printf("Enter a number :");
scanf("%d",&num);
if((num%5==0)&&(num%11==0))
{
printf("%d can divisible by 5 and 11",num);

}
else
{
printf("%d can not divisible by 5 and 11",num);
}

return 0;

}
[Link] a c programme to input any alphabet and check whether it is alphabet,digit or
special character

//Check alphabet,digit or special character

#include<stdio.h>
int main()
{
char x;
printf("Enter any :");
scanf("%c",&x);

if(x>='0' && x<='9')


{
printf("%c is a Digit",x);
}

else if((x>='a' && x<='z') || (x>='A' && x<='Z'))


{
printf("%c is a Alphabet",x);
}

else
{
printf(" special character");
}

return 0;
}

[Link] a c programme to input all sides of a triangle and check whether triangle is valid
or not

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter a b c value :");
scanf("%d %d %d",&a,&b,&c);
if((a+b+c)==180)
{
printf("The triangle is valid");
}
else
{
printf("Invalid");
}

return 0;

[Link] a c programme to input mark and print letter grade

//Letter grade

#include<Stdio.h>
int main()
{
int mark;
printf("Enter mark :");
scanf("%d",&mark);
if(mark>=100 || mark<=0)
{
printf("Invalid mark");
}

else if(mark>=80 && mark<=100)


{
printf("A+");
}

else if(mark>=70 && mark<=79)


{
printf("A");
}

else if(mark>=60 && mark<=69)


{
printf("A-");
}
else if(mark>=50 && mark<=59)
{
printf("B");
}
else if(mark>=40 && mark<=49)
{
printf("C");
}
else if(mark>=33 && mark<=39)
{
printf("D");
}

else
{
printf("Fail");
}
return 0;
}

[Link] a c programme to check whether year leap year or not

#include<stdio.h>
int main()
{
int year;

/*Input a year from user*/


printf("Enter year :");
scanf("%d",&year);
if(year%400==0)
{
printf("Leap year");
}

else if(year%4==0 && year%100!=0)


{
printf("Leap year",year);
}
else
{
printf("not Leap year",year);
}

return o;

[Link] a c programme to check whether a number is even or odd

#include<stdio.h>
int main()
{
int a;
printf("Enter a number :");
scanf("%d",&a);
if(a%2==0)
{
printf("%d number is even",a);
}

else
{
printf("%d number is odd",a);
}

getch();
}

[Link] a c programme to print sum of all even number between 1 to n

#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter n value : ");
scanf("%d",&n);
for (i=2; i<=n; i=i+2)
{
printf(" %d ",i);
sum=sum+i;

}
printf(" Sum=%d\n",sum);

return 0;

[Link] a c programme to find out the sum of series 7+20+33…….+up to 100

#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter n value : ");
scanf("%d",&n);
for (i=7; i<=n; i=i+13)
{
printf(" %d ",i);
sum=sum+i;
}
printf(" Sum=%d",sum);

return 0;
}

15..Write a c programme to find out the sum of series 1^2+2^2+3^2…….+n^2

#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter n value :");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
printf(" %d ",i);
sum=sum+i*i;
}
printf(" sum=%d\n",sum);

getch();

[Link] a c programme to find out the sum of all array elements

#include<stdio.h>
int main()
{
int num[100],sum=0,i,n;
printf("How many numbers :");
scanf("%d",&n);

for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}

for(i=0;i<n;i++)
{
sum=sum+num[i];
}

printf(" sum=%d\n",sum);
return 0;
}

[Link] a c programme to find minimum and maximum element in an array.

#include<stdio.h>
int main()
{
int num[50],n,i;
printf("How many numbers :");
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&num[i]);
}
int max=num[0];
for(i=1; i<n; i++)
{
if(max<num[i])
max=num[i];
}

int min=num[0];
for(i=1; i<n; i++)
{
if(min>num[i])
min=num[i];
}
printf("maximum=%d\n",max);
printf("manimum=%d\n",min);
getch();

[Link] a c programme and find output of the fibonacci series using array

#include<stdio.h>
int main()
{
int a[50],i,n;
printf("How many numbers :");
scanf("%d",&n);

a[0]=0;
a[1]=1;
for(i=2; i<n; i++)
{
a[i]=a[i-1]+a[i-2];
}
printf("\n");
for(i=0; i<n; i++)
{
printf("%d ",a[i]);
}
getch();
}

[Link] a C program to find length using string


#include <stdio.h>

#define MAX_SIZE 100 // Maximum size of the string

int main()

char text[MAX_SIZE]; /* Declares a string of size 100 */

int i;

int count= 0;

/* Input a string from user */

printf("Enter any string: ");

gets(text);

/* Iterate till the last character of string */

for(i=0; text[i]!='\0'; i++)

count++;

printf("Length of '%s' = %d", text, count);

return 0;

You might also like