programming like c, c++, java,python learn in free

Monday, May 25, 2020

C programming Question and Answer Day-2

6. Program to accept a number from user and print it’s square & cube.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,sqre,cube;
clrscr();
printf("Enter Number: ");
scanf("%d",&n);
sqre=n*n;
cube=n*n*n;
printf("\nSquare: %d\nCube: %d",sqre,cube);
getch();
}


7. Program to accept two values of a & b and swap their values.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%d",&b);
printf("\nBefore Swapping..\n A=%d, B=%d",a,b);
temp=a;
a=b;
b=temp;
printf("\nAfter Swapping..\n A=%d, B=%d",a,b);
getch();
}

8. Program to accept two number and print largest among them.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%d",&b);
if(a>b)
printf("Largest value is: %d",a);
else
printf("Largest value is: %d",b);
getch();
}

9. Program to accept a number and check whether the number is Positive, Negative or Zero.

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter number: ");
scanf("%d",&n);
if(n>0)
printf("Number is positive");
else if(n<0)
printf("Number is negative");
else
printf("Number is Zero");
getch();
}

10. Program to check whether the number is even or odd.

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter number: );
scanf("%d",&n);
if(n%2==0)
printf("Number is even");
else
printf("Number is odd");
getch();
}
Share:

0 comments:

Post a Comment

Unordered List

recentposts1
Powered by Blogger.

Text Widget

Featured Post

C programming Question and Answer Day-15

71. Program to check Niven number (Harshad number). #include<stdio.h> #include<conio.h> void main() {     int n, d, a, su...

Search This Blog

recent comments

recentcomments

Labels

[slideshow][technology]

vertical posts

[verticalposts][technology]

business

[business][grids]

ad space

ads 600

vehicles

[cars][stack]
[verticalposts][food]

our facebook page

about us

logo

Jupiter is a magazine responsive Blogger template. It has everything you need to make your blog stand out. This template is fully customizable and very flexible and we believe you will love it as much as we do.

Slide show

[people][slideshow]

health

[health][btop]

recent posts

recentposts1

Subscribe Us

random posts

randomposts2

Blog Archive

Recent Posts

top ads

Unordered List

recent

Pages

Theme Support

[socialcounter] [facebook][#][215K] [twitter][#][115K] [youtube][#][215,635] [rss][#][23M] [linkedin][#][21.5K] [instagram][#][600,300]