C Lab sheet 1 contains twenty programs(1 to 20),
Where as C Lab Sheet 2 contains twenty programs(21 to 40).
Where as C Lab Sheet 2 contains twenty programs(21 to 40).
i. Input / Output Functions
Simple Mathematical Program using C
- C program to display "Hello World"
- C Program to find sum of two numbers
- C Program to find the square of given number || Cube of given number
- C Program to find simple interest
- C Program to convert temperature from Centigrade (C) to Fahrenheit (F). Hint: f=1.8c+32
- C program to find area and circumference of a circle.
- C program that ask length and breath of a room. Find area and perimeter of a room.
- C Program to find remainder of two number
- C Program to convert minutes into hour and minutes || Converts Seconds into Hour, Minute and Seconds
- C program to input number of days and convert it into years, months and days.
- C Program to check whether the given number is divisible by 7 or not.
- C Program to test whether the given number is even or odd.
- C Program to input mark of computer science and check whether the student is pass or fail where the pass mark is 40.
- C Program that asks two numbers and displays the smaller one || greater one.
- C program to asks three numbers and display the greatest || smallest among them.
- C program to find the greatest || smallest number among four numbers.
- C Program to input a number and check whether it is positive, negative, or zero.
- C Program to find the middle number among three different numbers.
- C program that inputs cost price and selling price and determine whether there is profit or loss.
- C program to find the commission amount in the basis of sales amount as per the following conditions:
Sales Amount Commission
0-1000 5%-
1001-2000 10%
>2000 12% - C program to display 5,10,15,.....50
- C program to display 5,10,15,..... up to 50th terms
- C program to display 1,2,4,8,16,..... up to 10th terms
- C program to display 1,2,4,7,11,..... up to 10th terms
- C program to display 2,8,18,32,..... up to 10th terms
- C program to display 999,728,511,..... up to 10th terms
- C program to display 100,98,94,88,80,..... up to 10th terms
- C program to display 7,22,11,34,17,..... up to 10th terms(Hailstone Series)
- C program to display 0,1,1,2,3,5,8,13,..... up to 50th terms (Fibonacci Series)
- C program to display the series with their sum 1,2,3,4,..... up to 10th terms
- C program to display all even numbers from 2 to 20 and find their sum.
- C program to find the factorial of the given number.
The product of a given positive integer multiplied by all lesser positive integers: The quantity five factorial (5!) = 5x4 x 3 x 2 x 1 = 120. - C program to display factors of a supplied number.
- C program to check whether the supplied number is prime or composite.
- C program to display all prime numbers from 1 to 100.
- C program that asks a multi-digit number and calculates the sum of its individual digits.
- C program to display the reverse of a supplied number.
- C program to test whether the supplied number is Palindrome number or not.
- C program to check whether the given number is Armstrong or not.
- C program to display:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
ii. Selection Statement
Conditional Program without Loop using C
iii. Looping Statement
Looping Program using C
#include <stdio.h>
int main()
{
int i;
for(i=5;i<=50;i=i+5)
{
printf("%d\n",i);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,a=5;
for(i=0;i<50;i++)
{
printf("%d\n",a);
a=a+5;
}
return 0;
}
#include <stdio.h>
int main()
{
int i,a=1;
for(i=0;i<10;i++)
{
printf("%d\n",a);
a=a*2;
}
return 0;
}
#include <stdio.h>
int main()
{
int i,a=1;
for(i=0;i<10;i++)
{
a=a+i;
printf("%d\n",a);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,a;
for(i=1;i<=10;i++)
{
a=i*i*2;
printf("%d\n",a);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,ans;
for(i=10;i>=1;i--)
{
ans=i*i*i-1;
printf("%d\n",ans);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,ans=100,b=2;
for(i=0;i<10;i++)
{
printf("%d\n",ans);
ans=ans-b;
b=b+2;
}
return 0;
}
Start with any integer value greater than 0, say x. If x is even, then the next value in the series is x/2; if x is odd, then the next value in the series is 3x + 1. This type of series is called Hailstone series
#include <stdio.h>
int main()
{
int a=7,r,i;
for(i=0;i<10;i++)
{
printf("%d\n",a);
r=a%2;
if(r==0)
a=a/2;
else
a=a*3+1;
}
return 0;
}
An integer in the infinite sequence 0,1, 1, 2, 3, 5, 8, 13, ..... of which the first two terms are 0 and 1 and each succeeding term is the sum of the two immediately preceding is called Fibonacci Series.
#include <stdio.h>
int main()
{
int a=0,b=1,c,i;
for(i=0;i<10;i++)
{
printf("%d\n",a);
c=a+b;
a=b;
b=c;
}
return 0;
}
#include <stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<=10;i++)
{
printf("%d\t",i);
sum=sum+i;
}
printf("Sum of series from 1-10 is %d",sum);
return 0;
}
iv. Looping with Condition
Looping program with condition Program using C
#include <stdio.h>
int main()
{
int i,sum;
for(i=2;i<=20;i=i+2)
{
printf("%d\n",i);
sum=sum+i;
}
printf("Sum of even numbers from 2 to 20 is %d " , sum);
return 0;
}
#include <stdio.h>
int main()
{
int num,i,f=1;
printf("Enter any number : ");
scanf("%d",&num);
for(i=num;i>=1;i--)
{
f=f*i;
}
printf("\n Factorial of %d is %d",num,f);
return 0;
}
#include <stdio.h>
int main()
{
int num,i;
printf(" Enter any number : ");
scanf("%d",&num);
printf("Factors of %d are : ",num);
for(i=1;i<=num;i++)
{
if(num%i==0)
printf(" %d\n ",i);
}
return 0;
}
A prime number is an integer which has only two factors i.e. one and itself. For example: 17 is prime number because it is exactly divisible by 1 and 17 only.
#include <stdio.h>
int main()
{
int num,i,count=0;
printf("Enter a number");
scanf("%d",&num);
for( i=1;i<=num;i++)
{
if(num%i==0)
count++;
}
if(count==2)
printf("%d is prime number",num);
else
printf("%d is composite number",num);
return 0;
}
#include <stdio.h>
int main()
{
int num,i,count;
for(num=1;num<=100;num++)
{
count=0;
for(i=1;i<=num;i++)
{
if(num%i==0)
count++;
}
if(count==2)
printf(" %d\n ",num);
}
return 0;
}
#include <stdio.h>
int main()
{
int num,r,sum=0;
printf(" Enter any number ");
scanf("%d",&num);
while(num!=0)
{
r=num%10;
sum=sum+r;
num=num/10;
}
printf("Sum of individual digits is %d",sum);
return 0;
}
#include <stdio.h>
int main()
{
int num,a,r,sum=0;
printf("Enter any number ");
scanf("%d",&num);
a=num;
while(num!=0)
{
r=num%10;
sum=sum*10+r;
num=num/10;
}
printf("Reverse of %d is %d",a,sum);
return 0;
}
Hint: A word, phrase, or sequence that reads the same backwards as forwards is called Palindrome. Example : 121 , 101 etc
#include <stdio.h>
int main()
{
int num,a,r,sum=0;
printf("Enter any number ");
scanf("%d",&num);
a=num;
while(num!=0)
{
r=num%10;
sum=sum*10+r;
num=num/10;
}
if(a==sum)
printf(" %d is Palindrome Number",a);
else
printf(" %d is not Palindrome Number",a);
return 0;
}
An Armstrong number is a number which equal to the sum of the cubes of its individual digits. For example: 153 is an Armstrong number as-
153=(1)3+(5)3+(3)3=1+125+27=153
#include <stdio.h>
int main()
{
int num,a,r,sum=0;
printf("Enter any number");
scanf("%d",&num);
a=num;
while(num!=0)
{
r=num%10;
sum=sum+r*r*r;
num=num/10;
}
if(a==sum)
printf("%d is Armstrong number",a);
else
printf("%d is not Armstrong number",a);
return 0;
}
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf(" %d ",i);
}
printf("\n");
}
return 0;
}
1. Write a program in C language that asks a number and check whether it is odd or even.
2. Write a program in C language to display the series with their sum 1, 2, 3, 4 ... up to 10th terms.
3. Write a program in C language to input a number and then check whether the number is positive or negative or zero.[SEE 2078]
4. Write a program in C language to display the series 1,1,2,3,5,8 ... up to 10th terms.
5. Write a program in ‘C’ language to input two numbers and find greatest among two number.
6. Write a program in C language to convert days into respective years, months and days.
7. Write a program in C language to display first 10 odd numbers. [SEE 2078]
8. Write C program to display the series : 1,2,3,6,11,20,37 .... up to 10th terms
#include<stdio.h>
int main()
{
int a=1,b=2,c=3,d=0,i;
for(i=0;i<=10;i++)
{
printf(" %d ",a);
d=a+b+c;
a=b;
b=c;
c=d;
}
return (0);
}