20 Days C practise (2/1/2021 To 22/1/2021
1st Day :-
CONDITIONAL
👉 C program to Write accepts two integers and check whether they are equal or not.
soln:
#include<stdio.h>
int main()
{
int a,b;
printf(" Insert two number = ");
scanf(" %d %d", &a, &b);
if(a==b)
printf(" Number is equal ");
else
printf("Number is not equal ");
getch();
}
2. Write a C program to check whether a given number is even or odd.
sol:
#include <stdio.h>
int main(void)
{ int a;
printf(" Insert A number = ");
scanf(" %d",&a);
if(a%2!=0)
printf(" %d is Odd Number",a);
else
printf("%d is even Number",a);
getch();
}
3. Write a C program to check whether a given number is positive or negative.
sol:
#include<stdio.h>
void main()
{
int a;
printf(" Enter a number =");
scanf("%d",&a);
if( a>0)
printf(" Number is positive");
else
printf("number is negative");
getch();
}
4. Write a C program to find whether a given year is a leap year or not.
#include<stdio.h>
int main()
{
int year;
printf("Insert Your year = ");
scanf("%d",&year);
if(year%400==0|| (year%100!=0&&year%4==0))
printf(" %d is leap year",year);
else
printf("%d is not leap year",year);
getch();
5. Write a C program to read the age of a candidate and determine whether it is eligible for casting his/her own vote.
#include <stdio.h>
void main()
{
int vote_age;
printf("Input the age of the candidate : ");
scanf("%d",&vote_age);
if (vote_age<18)
{
printf("Sorry, You are not eligible to caste your vote.\n");
printf("You would be able to caste your vote after %d year.\n",18-vote_age);
}
else
printf("Congratulation! You are eligible for casting your vote.\n");
}
6.Write a C program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
sol:;
7.
#include<stdio.h>
int main()
{
int height;
printf("Insert height");
scanf("%d",&height);
if(height>120)
printf(" the man is dawf");
else if(height>100 && height<=120)
printf(" the man is midium");
else
printf("the man is short");
getch();
}
8.Write a C program to find the largest of three numbers.
#include<stdio.h>
int main()
{
int a,b,c;
printf("Insert three number = ");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("a number is large");
else
printf("c is large");
}
else
{
if(b>c)
printf(" b is large");
else
printf("c is large");
}
getch();
}
9.Write a C program to accept a coordinate point in a XY coordinate system and determine in which quadrant the coordinate point lies.
#include<stdio.h>
int main()
{
int a,b;// a and b are coordinate
printf("Enter two coordinate number");
scanf("%d %d",&a ,&b);
if(a>0&& b>0)
printf("first coordinate");
else if(a>0 && b<0)
printf("four coordinate");
else if("a<0 && b>0")
printf("2nd coordinate");
else
printf("3rd coordinate");
getch();
}
10. Write a C program to find the eligibility of admission for a professional course based on the following criteria.
Eligibility Criteria : Marks in Maths >=65 and Marks in Phy >=55 and Marks in Chem>=50 and Total in all three subject >=190 or Total in Maths and Physics >=140 ------------------------------------- Input the marks obtained in Physics :65 Input the marks obtained in Chemistry :51 Input the marks obtained in Mathematics :72 Total marks of Maths, Physics and Chemistry : 188 Total marks of Maths and Physics : 137 The candidate is not eligible.
Expected Output :
The candidate is not eligible for admission.
Expected Output :
The candidate is not eligible for admission.
11. Write a C program to calculate the root of a Quadratic Equation.
sol:
#include<stdio.h>
#include<math.h>
int main()
{
int a,c,b,d;
float x,x1,x2;
printf("Insert three number ");
scanf("%d %d %d",&a,&b,&c);
if(d==0)
{
x=(-b/2*a);
printf("One value for X, that is = %f",x);
}
else if(d>0)
{
x1=(-b+d)/2*a;
x2=(-b-d)/2*a;
printf("The Value of x1 is = %f",x1);
printf("The value of X2 is = %f",x2);
}
else
{
printf("Solution not found");
}
getch();
}
12. Write a C program to read roll no, name and marks of three subjects and calculate the total, percentage and division
sol:
Test Data :
Input the Roll Number of the student :784Input the Name of the Student :James
Input the marks of Physics, Chemistry and math : 70 80 90
Expected Output :
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80
Math : 90
Total Marks = 240
Percentage = 80.00
Division =First
SOL:
#include<stdio.h>
#include<string.h>
int main()
{
int r,p,c,m,total;
char n;
float avg;
printf("Insert your roll no = ");
scanf("%d",&r);
printf("Enter your Name ");
scanf("%s",&n);
printf("Insert Your physics, chemistry and math number : ");
scanf("%d %d %d",&p,&c,&m);
total=p+c+m;
avg=total/3;
if(avg>60)
printf("FIRST DIVITION");
else if((avg>40)&&(avg<60))
printf(" secound divition ");
else
printf("3rd divition");
printf("\nRoll No : %d\nName of Student : %s\n",r,n);
printf("Marks is Physics : %d\n",p);
printf("marks in chemistry : %d\n",c);
printf("Marks in Math : %d\n",m);
printf("total is %d \n avarage is %f",total,avg);
getch();
}
13. Write a C program to read temperature in centigrade and display a suitable message according to temperature state below :
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Test Data :
42
Expected Output :
Its very hot.
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Test Data :
42
Expected Output :
Its very hot.
sol:#include <stdio.h>
void
main()
{
int tmp;
printf("Input days temperature : ");
scanf("%d",&tmp);
if(tmp<0)
printf("Freezing weather.\n");
else if(tmp<10)
printf("Very cold weather.\n");
else if(tmp<20)
printf("Cold weather.\n");
else if(tmp<30)
printf("Normal in temp.\n");
else if(tmp<40)
printf("Its Hot.\n");
else
printf("Its very hot.\n");
getch();
}
14. Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene
Loop
1. Write a program in C to display the first 10 natural numbers.
Expected Output :
1 2 3 4 5 6 7 8 9 10
Expected Output :
1 2 3 4 5 6 7 8 9 10
Sol:
#include<stdio.h>
int main()
{
int i;
printf("1st 10 natural number is = ");
for(i=1;i<=10;i++)
printf("%d ",i);
getch();
}
2. Write a C program to find the sum of first 10 natural numbers.
Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
sol:
#include<stdio.h>
int main()
{
int i,sum=0;
printf("1st 10 natural number is = ");
for(i=1;i<=10;i++)
{
sum=sum+i;
printf("%d ",i);
}
printf("\n sum is %d " ,sum);
getch();
}
3. Write a program in C to display n terms of natural number and their sum.
Test Data : 7
Expected Output :
The first 7 natural number is :
1 2 3 4 5 6 7
The Sum of Natural Number upto 7 terms : 28
Test Data : 7
Expected Output :
The first 7 natural number is :
1 2 3 4 5 6 7
The Sum of Natural Number upto 7 terms : 28
sol
#include<stdio.h>
int main()
{
int term,i,sum=0;
printf(" Insert term number = ");
scanf("%d",&term);
printf("\n The 1st %d natural number are : ",term);
for(i=1;i<=term;i++)
{
printf("%d",i);
sum=sum+i;
}
printf("sum is %d",sum);
getch();
}
4. Write a program in C to read 10 numbers from keyboard and find their sum and average.
Test Data :
Input the 10 numbers :
Number-1 :2
...
Number-10 :2
Expected Output :
The sum of 10 no is : 55
The Average is : 5.500000
Test Data :
Input the 10 numbers :
Number-1 :2
...
Number-10 :2
Expected Output :
The sum of 10 no is : 55
The Average is : 5.500000
problem ase
sol
#include<stdio.h>
int main()
{
int i,sum=0;
float avg;
printf(" Insert the 10 number");
for(i=1;i<=10;i++)
{
printf("\n number_%d =",i);
scanf("%d,&i");
sum+=i;
}
printf(" \n The sum is %d",sum);
avg=sum/10.0;
printf(" \n \n average is %f",avg);
getch();
}
5. Write a program in C to display the cube of the number upto given an integer.
Test Data :
Input number of terms : 5
Expected Output :
Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
Number is : 5 and cube of the 5 is :125
Test Data :
Input number of terms : 5
Expected Output :
Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
Number is : 5 and cube of the 5 is :125
sol
#include<stdio.h>
int main()
{
int i,n;
printf(" Input the number of terms : ");
scanf("%d",&n);
for(i=1;i<=5;i++)
{
printf("Number is :%d and cube of 1%d is %d\n",i,i,i*i*i);
}
getch();
}
6. Write a program in C to display the multiplication table of a given integer.
Test Data :
Input the number (Table to be calculated) : 15
Expected Output :
15 X 1 = 15
...
...
15 X 10 = 150.
Test Data :
Input the number (Table to be calculated) : 15
Expected Output :
15 X 1 = 15
...
...
15 X 10 = 150.
#include<stdio.h>
int main()
{
int i,n;
printf("Insert the number (table to be calculated : ");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf("%d*%d=%d\n",n,i,n*i);
}
return 0;
}
7. Write a program in C to display the multipliaction table vertically from 1 to n.
Test Data :
Input upto the table number starting from 1 : 8
Expected Output :
Multiplication table from 1 to 8
1x1 = 1, 2x1 = 2, 3x1 = 3, 4x1 = 4, 5x1 = 5, 6x1 = 6, 7x1 = 7, 8x1 = 8
...
1x10 = 10, 2x10 = 20, 3x10 = 30, 4x10 = 40, 5x10 = 50, 6x10 = 60, 7x10 = 70, 8x10 = 80
Test Data :
Input upto the table number starting from 1 : 8
Expected Output :
Multiplication table from 1 to 8
1x1 = 1, 2x1 = 2, 3x1 = 3, 4x1 = 4, 5x1 = 5, 6x1 = 6, 7x1 = 7, 8x1 = 8
...
1x10 = 10, 2x10 = 20, 3x10 = 30, 4x10 = 40, 5x10 = 50, 6x10 = 60, 7x10 = 70, 8x10 = 80
problem ase
#include <stdio.h>
void main()
{
int j,i,n;
printf("Input upto the table number starting from 1 : ");
scanf("%d",&n);
printf("Multiplication table from 1 to %d \n",n);
for(i=1;i<=10;i++)
{
for(j=1;j<=n;j++)
{
if (j<=n-1)
printf("%dx%d = %d, ",j,i,i*j);
else
printf("%dx%d = %d",j,i,i*j);
}
printf("\n");
}
}
Comments
Post a Comment