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

PIC Assignment 2 220463

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

PIC Assignment 2 220463

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

Programming in C Assignment

Name:-Deepak Yadav
Roll No:-220463
Q.53] Program in c which will print Numbers From 10 to 20 (Using
while Loop).
Code:
#include<stdio.h>
int main()
{
int i=10;
printf("Name:-Deepak Yadav 220463\n");
while (i<=20)
{
printf("%d\n",i);
i++;
}
return 0;
}
Output:
Q.54] Write a C Program which will Print Sum and Average of n
Numbers.
Code:-
#include<stdio.h>
int main()
{
int i,n,sum=0,numbers=1;
float Average;
clrscr();
printf("Name:-Deepak Yadav 220463");
printf("\n Enter how many Numbers you want:-\n");
scanf("%d",&n);

printf("Enter the Elements One by One:-");


for (i=0;i<n;++i)
{
scanf("%d",&numbers);
sum=sum+numbers;
}
Average=sum/n;
printf("\n Sum of the %d numbers=%d",n,sum);
printf("\n Average of the %d Numbers=%2f",n,Average);
getch();
return 0;
}
Output:-

Q.55] Write a C Program which will Print your Name n Times.


Code:-
#include<stdio.h>
#include<conio.h>
int main()
{
char name[30];
int n,c;
clrscr();
printf("\n Enter your Name::");
scanf("%s",&name);
printf("How Many Times you want to Print your Name:");
scanf("%d",&n);
c=1;
while(c<=n)
{
printf("%d Name:%s\n",c,name);
c++;
}
getch();
return 0;
}
Output:-

Q.56. Write a C program which will print the sum of all the odd and
even numbers between 1 to n.
Code:-
#include
int main()
{
int i, number, Even_Sum = 0, Odd_Sum = 0;
clrscr();
printf("\n Please Enter the Maximum Limit Value : ");
scanf("%d", &number);
for(i = 1; i <= number; i++)
{
if ( i%2 == 0 ) { Even_Sum = Even_Sum + i; }
else
{ Odd_Sum = Odd_Sum + i; } }
printf("\n The Sum of Even Numbers upto %d = %d", number, Even_Sum);
printf("\n The Sum of Odd Numbers upto %d = %d", number, Odd_Sum);
getch();
return 0;
}
Output:-

Q.57. Write a C program which will print the sum and reverse
of n digit numbers.
Code: -
#include<stdio.h>
#include<conio.h>
int main()
{
int num,sum=0,rev=0,d,n;
clrscr();
printf("Enter the number: ");
scanf("%d",&n);
while(num)
{
d=num%10;
num=num/10;
sum=sum+d;
rev=rev*10+d;
}
printf("Sum of digits = %d",sum);
printf("\nReverse of the number = %d",rev);
getch( );
return 0;
}
Output:-

Q.58:- Write a C program to find LCM and GCD.


Code:-
#include<stdio.h>
#include<conio.h>
int main()
{
int a,m,n,b,LCM,GCD,t;
clrscr();
printf("Name:-Deepak Yadav 220463\n");
printf("Enter Values of M and N:");
scanf("%d %d",&m,&n);
a=m;
b=n;
if((m==0)||(n==0))
{
LCM=0;
GCD=0;
}
else
{
while(n!=0)
{
t=m%n;
m=n;
n=t;
}
GCD=m;
LCM=(a*b)/GCD;
}
printf("LCM=%d\n",LCM);
printf("GCD=%d",GCD);
getch();
return 0;
}
Output:-
Q.58:- Write a C Program to Find Prime Numbers
Code:-
#include<stdio.h>
#include<conio.h>
int main()
{
int num,i,flag;
char a;
clrscr();
do{
flag=0;
printf("Name:-Deepak Yadav 220463\n");
printf("Enter any Value:");
scanf("%d",&num);
for(i=2; i<=num/2; ++i)
{
if(num %i==0)
{
flag=1;
break;
}
}
if (num==1)
{
printf("1 is neither Prime nor Composite.\n");
}
else
{
if(flag==0)
{
printf("%d is a Prime Number.\n",num);
}
else
{
printf("%d is not a Prime Number.\n",num);
}
}
printf("Do you want to check another number?(Y/N):");
scanf("%c",&a);

}while (a=='y'|| a=='Y');


getch();
return 0;

}
Output:-

You might also like