0% found this document useful (0 votes)
159 views7 pages

Assignment # 07 of C-Language On MS-Word

The document contains 6 C programming examples that demonstrate the use of loops and arrays. The examples include: 1) Printing the first 3 even numbers using nested for loops; 2) Printing a right-angled number triangle using nested for loops; 3) Printing the reverse of a right-angled number triangle using nested for loops; 4) Printing hardcoded values stored in an array; 5) Taking inputted values and printing them using an array; 6) Taking user input for student details like name, address, phone etc. and storing them in arrays of strings and printing the collected details.

Uploaded by

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

Assignment # 07 of C-Language On MS-Word

The document contains 6 C programming examples that demonstrate the use of loops and arrays. The examples include: 1) Printing the first 3 even numbers using nested for loops; 2) Printing a right-angled number triangle using nested for loops; 3) Printing the reverse of a right-angled number triangle using nested for loops; 4) Printing hardcoded values stored in an array; 5) Taking inputted values and printing them using an array; 6) Taking user input for student details like name, address, phone etc. and storing them in arrays of strings and printing the collected details.

Uploaded by

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

Date: 14 – 05 - 2019

OBJECT : Practice of Looping & Arrays.

 Program # 01: Write a program to print first-three even and natural numbers.

o Source Code:

#include<stdio.h>
main(){
for(int i=2;i<=6;i+=2)
{
for(int j=1;j<=3;j+=1)
{
printf("%d %d\n",i,j);
}
printf("\n");
}
return 0;
}

o Output:
Date: 14 – 05 - 2019

 Program # 02: Write a program to print right-angle triangle in terms of numbers.

o Source Code:

#include<stdio.h>
main(){
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

o Output:
Date: 14 – 05 - 2019

 Program # 03: Write a program to print reverse of right-angle triangle in terms of


numbers.

o Source Code:

#include<stdio.h>
main(){
for(int i=5;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

o Output:
Date: 14 – 05 - 2019

 Program # 04: Write a program which prints ten hardcoded values using array.

o Source Code:

#include<stdio.h>
main(){
int arr[10]={4,9,16,25,36,49,64,72,81,100};
for(int i=0;i<=9;i++)
{
printf("%d\n",arr[i]);
}
return 0;
}

o Output:
Date: 14 – 05 - 2019

 Program # 05: Write a program which prints ten inputted values using array.

o Source Code:

#include<stdio.h>
main(){
int arr[10];
for(int i=0;i<=9;i++)
{
printf("Enter values :\n");
scanf("%d",&arr[i]);
}
for(int j=0;j<=9;j++)
{
printf("Inputted value is : %d\n",arr[j]);
}
return 0;
}

o Output:
Date: 14 – 05 - 2019

 Program # 06: Write a program which takes name,address,contact,email,etc from


user in the arrays of string and prints it in a sequential way.

o Source Code:

#include<stdio.h>
#include<stdlib.h>
main(){
char name[25],gender[8],email[20],ph_no[11],address[25];
int s_no,fee;
float height;
printf("\t\t Enter Student Information\n");
printf("Enter your Serial Number : ");
scanf("%d",&s_no);
printf("\nEnter your Name : ");
scanf("%s",&name);
printf("\nEnter your Fee : ");
scanf("%d",&fee);
printf("\nEnter your Gender : ");
scanf("%s",&gender);
printf("\nEnter your Address : ");
scanf("%s",&address);
printf("\nEnter your Phone Number : ");
scanf("%s",&ph_no);
printf("\nEnter your Email : ");
scanf("%s",&email);
printf("\nEnter your Height : ");
scanf("%f",&height);
system("cls");
printf("\n\t\t Student Information\n");
printf("\nSerial Number : %d\n",s_no);
printf("\nName : %s\n",name);
printf("\nFee : %d\n",fee);
printf("\nGender : %s\n",gender);
printf("\nAddress : %s\n",address);
printf("\nPhone Number : %s\n",ph_no);
printf("\nEmail : %s\n",email);
printf("\nHeight : %.2f\n",height);
return 0;
}
Date: 14 – 05 - 2019

o Output: (Before CLS)

o Output: (After CLS)

You might also like