0% found this document useful (0 votes)
5 views

Lab Assignment 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab Assignment 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name - Tanmay Shrivastava

Course-BTech(CSE)
Roll No.-24155589

Day 6(Lab Assignments)


Question1)WAP to print even series within 50.
#include <stdio.h>
int main()
{
int a;
a=2;
while(a<=50)
{
printf("%d ",a);
a=a+2;
OUTPUT:
}
return 0; 2 4 6 8 10...........48 50
}
Question2)WAP to print the natural numbers from 1 to n (value of n is user input).

#include <stdio.h> INPUT:


int main() Enter the number=10
{
int a,b;
printf("Enter the number=");
scanf("%d",&a);
b=1; OUTPUT:
while(b<=a) 1 2 3 4 5 6 7 8 9 10
{
printf("%d\t",b);
b=b+1;
}
return 0;
}
Question3)WAP to print the natural numbers from n to 1(value of n is user input).

#include <stdio.h>
int main() INPUT:
{ Enter the number=5
int a;
printf("Enter the number=");
scanf("%d",&a);
while(a>=1)
{
printf("%d\t",a);
a=a-1;
OUTPUT:
} 54321
return 0;
}
Question4)WAP to take 10 different numbers as input. Print their sum and average.

#include <stdio.h> INPUT:


int main() Enter the number=1
{ Enter the number=1
int n,i,a,b;
Enter the number=1......
n=0;
i=1; Enter the number=1
while(i<=10)
{
printf("Enter the number=");
scanf("%d",&a);
n+=a; OUTPUT:
i=i+1; Sum is 10 and average is 1
}
b=n/10.00;
printf("Sum is %d and average is
%d",n,b);
return 0;
}
Question5)WAP to find out the sum of digits of a number.

#include <stdio.h>
int main()
{
int a,s,l;
INPUT:
s=0; Enter the number=234
printf("Enter the number=");
scanf("%d",&a);
while(a>0)
{
l=a%10;
s+=l;
a=a/10; OUTPUT:
} The sum is 9
printf("The sum is %d",s);
return 0;
}
Question 6)WAP to find out the reverse of a number.

INPUT:
#include <stdio.h> Enter the number=634
int main()
{
int a,n;
printf("Enter the number=");
scanf("%d",&a);
while(a>0) OUTPUT:
{
n=a%10; 436
printf("%d",n);
a=a/10;
}
return 0;
}

You might also like