INTRODUCTION PROGRAMS
1)
#include<stdio.h>
main()
{
int x=10;
printf("x:-%d\n",x);
}
/*
output
x:-10
*/
main()
{
int x=10;
printf("x:-%d\n",x);
}
/*
output
x:-10
*/
2)
#include<stdio.h>
main()
{
float x=1.23;
printf("x:-%f\n",x);
}
/*
output
x:- 1.230000
*/
main()
{
float x=1.23;
printf("x:-%f\n",x);
}
/*
output
x:- 1.230000
*/
3)
#include<stdio.h>
main()
{
char x='v';
printf("x:-%c\n",x);
}
/*
output
x:- v
*/
main()
{
char x='v';
printf("x:-%c\n",x);
}
/*
output
x:- v
*/
4)simple program about scanf
#include<stdio.h>
main()
{
char x;
int y;
float z;
printf("enter char,interger ,float value\n");
scanf("%c",&x);
scanf("%d",&y);
scanf("%f",&z);
printf("-------------\n");
printf("%c\n%d\n%f\n",x,y,z);
}
#include<stdio.h>
main()
{
char x;
int y;
float z;
printf("enter char,interger ,float value\n");
scanf("%c",&x);
scanf("%d",&y);
scanf("%f",&z);
printf("-------------\n");
printf("%c\n%d\n%f\n",x,y,z);
}
5)write a program to add two numbers
#include<stdio.h>
main()
{
int x,y,z;
printf("enter the two numbers\n");
scanf("%d%d",&x,&y);
z=x+y;
printf("***output***\n");
printf("z:-%d\n",z);
}
#include<stdio.h>
main()
{
int x,y,z;
printf("enter the two numbers\n");
scanf("%d%d",&x,&y);
z=x+y;
printf("***output***\n");
printf("z:-%d\n",z);
}
6)write a program to print area of cirlce
#include<stdio.h>
main()
{
int r;
float a;
printf("enter radius\n");
scanf("%d",&r);
a=3.14*r*r;
printf("area of the cirlce:%f\n",a);
}
#include<stdio.h>
main()
{
int r;
float a;
printf("enter radius\n");
scanf("%d",&r);
a=3.14*r*r;
printf("area of the cirlce:%f\n",a);
}
7)write a program swapping or inter change two numbers(using third variable)
#include<stdio.h>
main()
{
int x,y,t;
printf("enter two numbers\n");
scanf("%d%d",&x,&y);
printf("Before changing\n");
printf("x:%d y:%d\n",x,y);
t=x;
x=y;
y=t;
printf("After changing\n");
printf("x:%d y:%d\n",x,y);
}
#include<stdio.h>
main()
{
int x,y,t;
printf("enter two numbers\n");
scanf("%d%d",&x,&y);
printf("Before changing\n");
printf("x:%d y:%d\n",x,y);
t=x;
x=y;
y=t;
printf("After changing\n");
printf("x:%d y:%d\n",x,y);
}
8)write a program swaping or inter changing two numbers (without using third variable)
#include<stdio.h>
main()
{
int x,y;
printf("enter two numbers\n");
scanf("%d%d",&x,&y);
printf("Before changing\n");
printf("x: %d y: %d\n",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("After changing\n");
printf("x:%d y:%d\n",x,y);
}
#include<stdio.h>
main()
{
int x,y;
printf("enter two numbers\n");
scanf("%d%d",&x,&y);
printf("Before changing\n");
printf("x: %d y: %d\n",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("After changing\n");
printf("x:%d y:%d\n",x,y);
}
9)write a program to add,sub,multi,divide and find remainder of the two numbers
#include<stdio.h>
main()
{
int x,y,a,b,c,e;
float d;
printf("enter two numbrs\n");
scanf("%d%d",&x,&y);
a=x+y;
b=x-y;
c=x*y;
d=x/(float)y;
e=x%y;
printf("add:%d sub:%d mul:%d divide:%f reminder:%d\n",a,b,c,d,e);
}
#include<stdio.h>
main()
{
int x,y,a,b,c,e;
float d;
printf("enter two numbrs\n");
scanf("%d%d",&x,&y);
a=x+y;
b=x-y;
c=x*y;
d=x/(float)y;
e=x%y;
printf("add:%d sub:%d mul:%d divide:%f reminder:%d\n",a,b,c,d,e);
}
10)Pre-increment & Post-increment
//Pre-decrement & Post-decrement
#include<stdio.h>
main()
{
int x = 10;
printf("Pre-increment & Post-increment");
printf("x :%d\n",x);
printf("x :%d\n",x++);
printf("x :%d\n",x);
printf("x :%d\n",++x);
printf("x :%d\n",x);
printf("x :%d\n",x);
printf("x :%d\n",++x);
printf("x :%d\n",x);
printf("x :%d\n",x++);
printf("x :%d\n",x);
printf("Pre-decrement & Post-decrement");
printf("x :%d\n",x);
printf("x :%d\n",x--);
printf("x :%d\n",x);
printf("x :%d\n",--x);
printf("x :%d\n",x);
printf("x :%d\n",x);
printf("x :%d\n",--x);
printf("x :%d\n",x);
printf("x :%d\n",x--);
printf("x :%d\n",x);
}
//Pre-decrement & Post-decrement
#include<stdio.h>
main()
{
int x = 10;
printf("Pre-increment & Post-increment");
printf("x :%d\n",x);
printf("x :%d\n",x++);
printf("x :%d\n",x);
printf("x :%d\n",++x);
printf("x :%d\n",x);
printf("x :%d\n",x);
printf("x :%d\n",++x);
printf("x :%d\n",x);
printf("x :%d\n",x++);
printf("x :%d\n",x);
printf("Pre-decrement & Post-decrement");
printf("x :%d\n",x);
printf("x :%d\n",x--);
printf("x :%d\n",x);
printf("x :%d\n",--x);
printf("x :%d\n",x);
printf("x :%d\n",x);
printf("x :%d\n",--x);
printf("x :%d\n",x);
printf("x :%d\n",x--);
printf("x :%d\n",x);
}
LOOPS
IF-ELSE
11)Write a program to check the given no is positive. (using if)
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x>0)
{
printf("%d IS POSSITIVE NUMBER\n",x);
}
}
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x>0)
{
printf("%d IS POSSITIVE NUMBER\n",x);
}
}
12)Write a program to check the given no is even. (using if)
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x%2==0)
{
printf("%d is even\n",x);
}
}
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x%2==0)
{
printf("%d is even\n",x);
}
}
13)Write a program to check the given no is positive or negative. (using if-else)
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x>0)
{
printf("%d positive number\n",x);
}
else
{
printf("%d negative number\n",x);
}
}
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x>0)
{
printf("%d positive number\n",x);
}
else
{
printf("%d negative number\n",x);
}
}
14)Write a program to check the given no is even or odd. (using if-else)
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x%2==0)
{
printf("%d is even\n",x);
}
else
{
printf("%d is odd\n",x);
}
}
#include<stdio.h>
main()
{
int x;
printf("enter any number\n");
scanf("%d",&x);
if(x%2==0)
{
printf("%d is even\n",x);
}
else
{
printf("%d is odd\n",x);
}
}
15)Write a program to print greatest of two nos. (using if-else)
#include<stdio.h>
main()
{
int s,g;
printf("enter two numbers\n");
scanf("%d%d",&s,&g);
if(s>g)
{
printf("%d is greatest\n",s);
}
else
{
printf("%d is greatest\n",g);
}
}
#include<stdio.h>
main()
{
int s,g;
printf("enter two numbers\n");
scanf("%d%d",&s,&g);
if(s>g)
{
printf("%d is greatest\n",s);
}
else
{
printf("%d is greatest\n",g);
}
}
16)Write a program to check the given two nos are equal or not equal. (using if-else)
#include<stdio.h>
main()
{
int g,s;
printf("enter two numbers\n");
scanf("%d%d",&g,&s);
if(s==g)
{
printf("equal\n");
}
else
{
printf("not equal\n");
}
}
#include<stdio.h>
main()
{
int g,s;
printf("enter two numbers\n");
scanf("%d%d",&g,&s);
if(s==g)
{
printf("equal\n");
}
else
{
printf("not equal\n");
}
}
17)Write a program to print greatest of three nos. (using nested - if)
#include<stdio.h>
main()
{
int x,y,z;
printf("enter three numbrs\n");
scanf("%d%d%d",&x,&y,&z);
if(x>y && x>z)
{
printf("%d ids greatest\n",x);
}
else
{
if(y>z)
{
printf("%d is greatest\n",y);
}
else
{
printf("%d is greatest\n",z);
}
}
}
#include<stdio.h>
main()
{
int x,y,z;
printf("enter three numbrs\n");
scanf("%d%d%d",&x,&y,&z);
if(x>y && x>z)
{
printf("%d ids greatest\n",x);
}
else
{
if(y>z)
{
printf("%d is greatest\n",y);
}
else
{
printf("%d is greatest\n",z);
}
}
}
18)Write a program to find total, average & grade of the student when three subjects are given.
#include<stdio.h>
main()
{
int s1,s2,s3,total;
float percentage;
printf("enter three subjects marks\n");
scanf("%d%d%d",&s1,&s2,&s3);
total=s1+s2+s3;
percentage=total/3.0;
printf("s1:%d\n",s1);
printf("s2:%d\n",s2);
printf("s3:%d\n",s3);
printf("total:%d\n",total);
printf("percentage:%f\n",percentage);
if(s1>=35&&s2>=35&&s3>=35)
{
if(percentage>=75)
{
printf("distinction\n");
}
else
{
if(percentage>=60)
{
printf("1st class\n");
}
else
{
if(percentage>=50)
{
printf("2nd class\n");
}
else
{
printf("3rd class\n");
}
}
}
}
else
{
printf("fail\n");
}
}
#include<stdio.h>
main()
{
int s1,s2,s3,total;
float percentage;
printf("enter three subjects marks\n");
scanf("%d%d%d",&s1,&s2,&s3);
total=s1+s2+s3;
percentage=total/3.0;
printf("s1:%d\n",s1);
printf("s2:%d\n",s2);
printf("s3:%d\n",s3);
printf("total:%d\n",total);
printf("percentage:%f\n",percentage);
if(s1>=35&&s2>=35&&s3>=35)
{
if(percentage>=75)
{
printf("distinction\n");
}
else
{
if(percentage>=60)
{
printf("1st class\n");
}
else
{
if(percentage>=50)
{
printf("2nd class\n");
}
else
{
printf("3rd class\n");
}
}
}
}
else
{
printf("fail\n");
}
}
No comments:
Post a Comment