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

C Programs Week4

The document contains C programs for various tasks including displaying a name multiple times, printing numbers from 1 to 10 using a while loop, showing even numbers below 20 with a do-while loop, and calculating the sum of the first 20 natural numbers using a for loop. Each program includes the necessary code and prompts for user input. These examples illustrate basic programming concepts and control structures in C.

Uploaded by

boddanaomkar
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 views2 pages

C Programs Week4

The document contains C programs for various tasks including displaying a name multiple times, printing numbers from 1 to 10 using a while loop, showing even numbers below 20 with a do-while loop, and calculating the sum of the first 20 natural numbers using a for loop. Each program includes the necessary code and prompts for user input. These examples illustrate basic programming concepts and control structures in C.

Uploaded by

boddanaomkar
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/ 2

C PROGRAMS

WEEK 4

PROGRAM-12
12. Write a C Program to display Your name 5 times

Program
#include<stdio.h>
int main()
{
int i,n;
printf("Enter the Number of times: \t");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf(" %d Ganesh \n",i);
return 0;
}

PROGRAM-13
13. Write a C Program to display 1 to 10 Numbers using while loop.

Program
#include<stdio.h>
int main()
{
int i=1,n;
printf("Enter the Number: \t");
scanf("%d",&n);
while(i<=n)
{
printf(" %d \n",i);
i++;
}
return 0;
}
PROGRAM-14
14. Write a C Program to display even numbers below 20 using do-
while loop.

Program
#include<stdio.h>
int main()
{
int i=1,n;
printf("Enter the Number: \t");
scanf("%d",&n);
do
{
if(i%2==0)
printf(" %d \n",i);
i++;
}while(i<=n);
return 0;
}

PROGRAM-15
15. Write a C Program to display sum of 20 natural numbers using
for loop.

Program
#include<stdio.h>
int main()
{
int n,sum=0;
printf("Enter the Number: \t");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
sum=sum+i;
}
printf(" The Sum of first %d numbers is %d \n",n,sum);
return 0;
}

You might also like