0% found this document useful (0 votes)
3 views10 pages

PPS Assignment

Uploaded by

Deepanshi Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

PPS Assignment

Uploaded by

Deepanshi Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

NAME-DEEPANSHI

ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

1. Write a program to find the sum of digits of a


number and also write it in reverse order.

#include<stdio.h>
int main()
{
int n,r,s=0,rev=0;
printf("Enter a number:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s+r;
rev=rev*10+r;
n=n/10;
}
printf("Sum of digits:%d\n",s);
printf("Reverse of the number is:%d",rev);
}
Example output screen-
NAME-DEEPANSHI
ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

2. Write a program to find the largest number out of


ten/N numbers (for- statement)
#include<stdio.h>
int main()
{
int n,i,large=0,ele;
printf("Enter total no. of observations:");
scanf("%d",&n);
printf("Enter %d elements:",n);
for(i=1;i<=n;i++)
{
scanf("%d",&ele);
if(ele>large)
{
large=ele;
}
}
printf("Largest number is:%d",large);
}
Example output screen-
NAME-DEEPANSHI
ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

3. Write a program to add, subtract, multiply and


divide two numbers using menu driven program.
#include<stdio.h>
int main()
{
int a,b,c,add,sub,mul,div;
printf("Enter two numbers:\n");
scanf("%d%d",&a,&b);
printf("1.add\n2.sub\n3.mul\n4.div\n");
printf("Enter your choice");
scanf("%d",&c);
switch(c)
{
case 1: add=a+b;
printf("Addition is:%d\n",add);
break;
case 2: sub=a-b;
printf("Subtraction is:%d\n",sub);
break;
case 3: mul=a*b;
printf("Multiplication is:%d",mul);
break;
case 4: div=a/b;
printf("Division is:%d",div);
break;
default: printf("Invalid choice\n");
}
}

Example output screen-


NAME-DEEPANSHI
ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

4. Write a program to find factorial of a number.


#include<stdio.h>
int main()
{
int num,fac=1,i;
printf("Enter a number:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fac=fac*i;
}
printf("Factorial is:%d",fac);
}
Example output screen-
NAME-DEEPANSHI
ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

5. Write a program to calculate the length of the


string.
#include<stdio.h>
int main()
{
char s[20];
int i;
printf("Enter a string");
gets(s);
for(i=0;s[i]!='\0';i++);
printf("Length is:%d",i);
}

Example output screen-


NAME-DEEPANSHI
ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

6. Write a program to demonstrate the concept of


“call by value”.
#include<stdio.h>
int sum(int a,int b)
{
return (a+b);
}

int main()
{
int a,b,c;
a=9;
b=83;
c=sum(a,b);
printf("Sum is:%d",c);
return 0;
}

Example output screen-


NAME-DEEPANSHI
ROLL NO.-200151520010
BRANCH-ECE
2nd SEMESTER

7. Write a program to demonstrate the concept of


“call by reference”.

#include<stdio.h>
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
int main()
{
int a=30,b=70;
printf("%d and %d\n",a,b);
swap(&a,&b);
printf("%d and %d\n",a,b);
return 0;
}
Example output screen-

You might also like